How do I kill a sprite on world bounds out for matter physics? Or is there a better way?
I ran into a similar situation. Arcade physics has an ARCADE_WORLD_BOUNDS_EVENT, but I wasn't able to find a similar event for Matter.js physics. There doesn't (yet) seem to be a convenient way to detect this via a single event for Matter.js.
I do see collision events with the boundary objects when listening for this.physics.world.events.on('COLLISION_START_EVENT', so that could be an workaround for now? You'll need to figure out if one of the collision targets is a boundary manually.
I'm guessing this something that will be implemented in the future :)
In my case, I ended up not using boundaries and instead check if the position of the sprite is off screen and remove it.
I'm closing this one, as it's a question.
Sorry, I know this is closed, but here is how I dealt with identifying bounds in phaser3 with matter.
let bounds = this.matter.world.setBounds(0, 0, this.level.map.w, this.level.map.h);
Object.values(bounds.walls).forEach(o => o.label = 'bounds')
When you first define the world bounds, loop over the walls object and assign a label to each wall. Then on a collision event, you can access the body label in the returned pair value.
For instance:
onPlayerCollide({gameObjectB, pair}) {
if (pair.bodyA.label == 'bounds') {...}
})
Here I found a great plugin for collision detection:
https://github.com/mikewesthad/phaser-matter-collision-plugin/stargazers
I had to access the labels directly e.g.
bounds.walls.left.label = 'lol';
Most helpful comment
I ran into a similar situation. Arcade physics has an
ARCADE_WORLD_BOUNDS_EVENT, but I wasn't able to find a similar event for Matter.js physics. There doesn't (yet) seem to be a convenient way to detect this via a single event for Matter.js.I do see collision events with the boundary objects when listening for
this.physics.world.events.on('COLLISION_START_EVENT', so that could be an workaround for now? You'll need to figure out if one of the collision targets is a boundary manually.I'm guessing this something that will be implemented in the future :)
In my case, I ended up not using boundaries and instead check if the position of the sprite is off screen and remove it.