Stemkoski Posted September 30, 2013 Share Posted September 30, 2013 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 More sharing options...
RestingCoder Posted September 30, 2013 Share Posted September 30, 2013 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 More sharing options...
Stemkoski Posted September 30, 2013 Author Share Posted September 30, 2013 Thanks for the pointer! It appears as though you can use just a standard function. The code I ended up using was:bullet.events.onOutOfBounds.add( goodbye, this );and elsewhere:function goodbye(obj) { obj.kill();} RestingCoder 1 Link to comment Share on other sites More sharing options...
spider Posted December 4, 2013 Share Posted December 4, 2013 I may be mistaken, but kill() doesn't kill it a sprite completely. You can always revive() a killed sprite. The destroy() method will be a better option methinks. Arlefreak 1 Link to comment Share on other sites More sharing options...
Recommended Posts