Sign in to follow this  
Stemkoski

Destroy off-screen sprites using events

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?

 

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.