ylluminarious Posted July 28, 2014 Share Posted July 28, 2014 I'm trying to find an easy way to check if a sprite has gone past world boundaries. Basically, I want something like this:if (sprite.outOfWorldBounds === true) { // do stuff} I know that I could just check a sprite's coordinates on the world, but I'm wondering if Phaser has a better way of dealing with this. Link to comment Share on other sites More sharing options...
lewster32 Posted July 28, 2014 Share Posted July 28, 2014 http://docs.phaser.io/Phaser.Sprite.html#checkWorldBounds Link to comment Share on other sites More sharing options...
lewster32 Posted July 28, 2014 Share Posted July 28, 2014 Though if you can do it via x/y checking in the update loop, prefer that method, as it'll be faster. Link to comment Share on other sites More sharing options...
ylluminarious Posted July 28, 2014 Author Share Posted July 28, 2014 @lewster32 Thanks for the answer I am wondering, though, is there a way to assign your own function to `sprite.events.onOutOfBounds`, as I would like the sprite to do a specific thing once it leaves the world? Link to comment Share on other sites More sharing options...
lewster32 Posted July 28, 2014 Share Posted July 28, 2014 Yes - it's an instance of a Signal which has all of the usual methods open to it, so in your case:sprite.events.onOutOfBounds.add(function() { // ... this sprite has gone out of bounds, so perform your magic here!}, this); Link to comment Share on other sites More sharing options...
ylluminarious Posted July 28, 2014 Author Share Posted July 28, 2014 Thanks, that worked. Link to comment Share on other sites More sharing options...
Recommended Posts