Jump to content

Collision callback on world border


Recommended Posts


I have a custom actor (extended from Phaser.Sprite) that is controlled by the user. I want the actor to be able to shoot the children of a enemies group. To do this I create a new sprite every time the user wants to shoot and add it to a bullets group. The sprite is accelerated in the direction that the actor is looking to.

Everything works fine, and the bullet and the enemy get killed if they overlap. When the bullet overlaps somthing different than an enemy only the bullet gets destroyed.
The Problem is that the bullets will not be destroyed if they reach the world bounds.

Is there any way to detect collision between the bullet sprite and the world bounds?

Is there a built in way to do this? If not, what is the better practice:

  1. Iterate over every bullet (most time not more then 10 bullets at the same time) in the update function to check if it has left the world
  2. Create invisible sprites at every world border and check for collisions between them and the bullets

I am new to this forum and also new to phaser. Sorry if the answer to my question is very simple.

Thanks in advance, Paul

Link to comment
Share on other sites

Welcome to the forum! Phaser's community is one of its biggest draws to me.

Sprites have a property called "outOfBoundsKill". Set that to true and they'll be killed when they're out of world bounds.

You could also give them a lifetime in milliseconds and, once exceeded, kill them.

Iterating over 10 or so in a for-loop doesn't sound like a bad solution, either. Invisible sprites just over the world bounds seems reasonable too.

Link to comment
Share on other sites


  • Recently Browsing   0 members

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