Jump to content

Destroy off-screen sprites using events


Stemkoski
 Share

Recommended Posts

I've been looking through the Phaser source code for the "right" or "developer-intended" way to remove a sprite from the game when it moves off-screen.  There appears to be an "inWorld" property that I can check. Excellent! But even better, I saw something called "onOutOfBounds" that appears to automatically check for this condition and trigger a Phaser.Event or a Phaser.Signal -- and here it gets a bit murky for me. I suspect that after creating a sprite (called "bullet" for instance) I should be able to handle this behavior by coding something like:

 

    bullet.events.onOutOfBounds.add( ??? );

 

where ??? involves a call to kill() (or destroy() when it is added to the library). Any thoughts on what ??? should be?

 

Link to comment
Share on other sites

I believe one of the examples has some commented code for this, but do not have time to check which one. It was either Invaders or one of the particle ones. If it is Invaders, it is to kill bullets that go off screen.

 

Edit:  I had a free minute, and checked. http://gametest.mobi/phaser/examples/games/invaders.php shows how to do this. I am not sure if it is commented out because it is not finished, or what. Try it out and see if it works.

Link to comment
Share on other sites

  • 2 months later...
 Share

  • Recently Browsing   0 members

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