mhcdotcom Posted October 29, 2018 Share Posted October 29, 2018 Hey All, var bomb = this.bombs.create(this.enemy1.x, this.enemy1.y, 'bomb'); bomb.setGravityY(-1500); bomb.body.velocity.x = -400; bomb.outOfBoundsKill = true; The bomb appears as expected. With the above in place I don't get any console errors. I got the `bomb.outOfBoundsKill = true;` reference from multiple Phaser 2 resources but cannot find the equivalent for phaser 3. I want to confirm it is being destroyed as expected but I cannot find a method for firing a callback when an image instance leaves the world bounds. I saw this one: `bomb.events.onOutOfBounds.add(functionName, this)` but this fires errors in the console. If you could help me understand what is going on here, it would be much appreciated. Link to comment Share on other sites More sharing options...
samme Posted October 30, 2018 Share Posted October 30, 2018 Phaser 3 has no Bullet class and no outOfBoundsKill property. You can use the worldbounds event. mhcdotcom 1 Link to comment Share on other sites More sharing options...
mhcdotcom Posted November 1, 2018 Author Share Posted November 1, 2018 On 10/30/2018 at 2:20 PM, samme said: Phaser 3 has no Bullet class and no outOfBoundsKill property. You can use the worldbounds event. I don't know what a bullet classe is. The worldbounds event is useful for when the balls are set to collide with the world bounds(collideWorldBounds = true). I want to detect when the ball has left the game world bounds when collideWorldBounds = false. Reason being, I want entities to get destroyed once they have left the world bounds so performance doesn't suffer. I'm seeing now after some research I could do something like: if (bomb < this.scene.physics.world.bounds.left) { bomb.destroy() } Would that be an ideal method for what I want to accomplish? Thanks for your time Link to comment Share on other sites More sharing options...
samme Posted November 1, 2018 Share Posted November 1, 2018 https://codepen.io/samme/pen/MPNpEa?editors=0010 mhcdotcom 1 Link to comment Share on other sites More sharing options...
mhcdotcom Posted November 1, 2018 Author Share Posted November 1, 2018 (edited) Thanks @samme I appreciate your time. Your method for removing the bomb looks good. Ideally i still want the bomb sprites to leave the screen before being disabled, with your method the bomb disappears as soon as it touches the world bounds. What is the difference between bomb.disableBody(true, true) and bomb.destroy() ? Is the method I mentioned in my previous comment not ideal? I could update it to look like if (bomb < this.scene.physics.world.bounds.left+bomb.width) { bomb.destroy()// or bomb.disableBody(true, true) } to ensure it is completely offscreen. I hope you can still help. Thanks again. Edited November 1, 2018 by mhcdotcom clarity Link to comment Share on other sites More sharing options...
samme Posted November 2, 2018 Share Posted November 2, 2018 Yes, you can check world.bounds directly in update() and that may work better. You can use ContainsRect as well. After disableBody a Game Object can be reset/reactivated later. After destroy it can't. mhcdotcom 1 Link to comment Share on other sites More sharing options...
mhcdotcom Posted November 2, 2018 Author Share Posted November 2, 2018 12 minutes ago, samme said: Yes, you can check world.bounds directly in update() and that may work better. You can use ContainsRect as well. After disableBody a Game Object can be reset/reactivated later. After destroy it can't. Awesome. Thanks for your help. Link to comment Share on other sites More sharing options...
Recommended Posts