Phaser 3阵列碰撞

Phaser 3 array collison

在移相器 3 中,我使用重叠来检查碰撞。我的代码如下:

//bulletA is an array(one of the 2 arrays where collison is being checked) it contains all my bullet sprites
//enemy1 is an array containing all the enemies, which I am testing for collision with my bullets. It contains all my enemy sprites
this.physics.add.overlap(bulletA, enemy1, collide1, null, this);

碰撞检测工作正常(我在碰撞时使用 console.log 进行了测试)。但是,我需要能够分辨出 enemy1 数组中哪个特定的敌人精灵与我的子弹发生碰撞。这需要发生,以便我可以在敌人身上播放爆炸动画,并将特定的敌人从游戏中移除。有什么方法可以获取正在使用重叠的数组的特定元素吗?

overlap 函数接受一个回调,return 两个碰撞对象
https://photonstorm.github.io/phaser3-docs/Phaser.Physics.Arcade.ArcadePhysics.html#overlap

例如

overlap(bulletA, enemy1, collide1)

function collide1 (ob1, ob2) {
  // ob1 is the bullet that collided with the enemy
  // ob2 is the enemy that collided with the bullet
}