I have 10 images moving towards rectangles. I want to stop each one when it hits a rectangles, and remove the collider when all of them have stopped:
let hits = new Set();
let hands = scene.hands;
let w = scene.physics.world;
let col = scene.physics.add.overlap(og, rg, function(go, rect){
go.body.stop();
hits.add(go);
console.log('collided : '+hits.size);
if (hits.size == data.length) {
console.log("removing collider");
w.removeCollider(col);
}
});
This works but, surprisingly, I see multiple “collided: 10” and “removing collider” message pairs. Is this safe? Is there a better way to do this?