Out of bounds checking

Is there the built in way to check if object body is completely out of bounds? Or should I check each of body bounds coordinates in update method? It may pretty expensive for group of objects isn’t it? In case of tasks that not require much precise (such as onOutOfBoundsKill simulation), it can be optimized using looped timer instead of update I think, but if the task presumes to know exactly moment when object leave world bounds…

You might use a Sprite Group, a Physics Group, or a Container… However I’m not sure which to use when and it would be interesting if something else could explain.

For such a simple bounds check, maybe that is not necessary…
I would probably try adding a clean up function that destroyed (if that’s what you want) any objects that traveled outside of the world bounds.

Or you can call the destroy method when it collides with the world bounds.

See:

https://photonstorm.github.io/phaser3-docs/Phaser.Physics.Arcade.World.html

https://photonstorm.github.io/phaser3-docs/Phaser.GameObjects.Group.html

https://photonstorm.github.io/phaser3-docs/Phaser.Physics.Arcade.Group.html

https://photonstorm.github.io/phaser3-docs/Phaser.GameObjects.Container.html

Hopefully helpful…

1 Like

Another idea is to attach a listener to the object that waits for the coordinates to go out of bounds, and then calls a method to handle it (destroy, move, recycle, etc), but I have not tested this.

Here is a relevant answer to a similar question:

I decide to use world bounds overlap checking:
Phaser.Geom.Rectangle.Overlaps(this.scene.physics.world.bounds, sprite.getBounds())
If the returning value is false, than the object is completely out of bounds.

3 Likes