P4UL Posted July 7, 2016 Share Posted July 7, 2016 Hello! 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: 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 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 More sharing options...
drhayes Posted July 7, 2016 Share Posted July 7, 2016 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. P4UL 1 Link to comment Share on other sites More sharing options...
P4UL Posted July 7, 2016 Author Share Posted July 7, 2016 Thank you very much for your answer! The "outOfBoundsKill" property worked perfect for me and the code is much cleaner than iterating over every bullet. Link to comment Share on other sites More sharing options...
drhayes Posted July 8, 2016 Share Posted July 8, 2016 Happy to help. Come join the Slack channel and make fun of the giphy integration with us! Link to comment Share on other sites More sharing options...
Recommended Posts