【问题标题】:Phaser 3 array collisonPhaser 3 阵列碰撞
【发布时间】:2020-12-01 19:18:58
【问题描述】:

在移相器 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 数组中的哪个特定敌人精灵与我的子弹相撞。这需要发生,以便我可以在敌人身上播放爆炸动画,然后从游戏中删除那个特定的动画。有什么方法可以获取使用重叠的数组的特定元素吗?

【问题讨论】:

标签: javascript phaser-framework


【解决方案1】:

overlap 函数接受一个回调,返回两个碰撞的对象
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
}

【讨论】:

  • 感谢您的帮助!我没有意识到该函数返回了这些值。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-09-27
  • 2020-11-24
  • 1970-01-01
  • 1970-01-01
  • 2016-08-24
  • 2022-10-14
相关资源
最近更新 更多