Get reference to overlapped group element


#1

I have a group of batteries and a player. I want to check if player overlapped a battery:

var isOverlapping = TopDownGame.game.physics.arcade.overlap(player, batteries, null, null, this);
if (isOverlapping) {
    //reference to overlapped battery ??
}

But how to get reference element of batteries group which I overlapped with?
I can’t use common method like game.physics.arcade.overlap and that handle callback because I do all this not in game loop.


#2

In this example we see how to add an element to a group https://phaser.io/examples/v2/groups/add-a-sprite-to-group

AFAIK, if your group is called batteries the overlap method should fires on every element of the group, but to get a specifical battery it has to be referenced somewhere

So to continue on this way I think you have to look at the space invaders example on the site because it kills one ship at a time but am not sure it uses’s the group method


#3

Use the arguments passed to overlapCallback.


#4

Thank you!