Jump to content

Spawn random object (baloon) with specific ID


Phempt
 Share

Recommended Posts

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?

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...