Phempt Posted September 27, 2014 Share Posted September 27, 2014 Hello guys, I'm trying to spawn an object randomly from the bottom. I wrote this into the init function:createBaloon = function(){ randomNum = Math.floor(Math.random() * 320) + 1; console.log(randomNum); baloon = new game.Sprite('logo.png'); baloon.position.set(randomNum, 800); baloon.scale.set(0.2, 0.2); game.scene.stage.addChild(baloon); baloon.interactive = true; setTimeout("createBaloon();", 5000);}createBaloon(); baloon.touchstart = baloon.click = function() { game.audio.playSound('step'); this.remove(); }and this as update function:update: function() { if(baloon.position.y > '-150' ){ //console.log(baloon.position.y); baloon.position.y -= 100 * game.system.delta; // move sprite using delta time } else { baloon.remove(); } }it works and a lot of baloon are spawned. But there are 2 problems:1) only the first one is clickable;2) when a new baloon spawn, the previous one stop working (the update function not work on the new old one);Any idea? Quote Link to comment Share on other sites More sharing options...
Phempt Posted September 27, 2014 Author Share Posted September 27, 2014 Solved I used an array, but if you know a better method, please share Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.