尝试使用game.physics.arcade.overlap()来实现地精和子弹之间的碰撞。
提前感谢。
function update() {
game.physics.arcade.overlap(bullets, goblinSprite, bulletHitEnemy, null, this);
//Shoot on LeftMouse click
game.input.onDown.add(fire, this);
}
function bulletHitEnemy (goblinSprite, bullet) {
console.log('collision');
bullet.kill();
goblinSprite.kill();
}
function fire() {
if (game.time.now > nextFire && bullets.countDead() > 0)
{
nextFire = game.time.now + fireRate;
var bullet = bullets.getFirstDead();
bullet.reset(sprite.x + 5, sprite.y + 5);
game.physics.arcade.moveToPointer(bullet, 500);
}
}
答案 0 :(得分:0)
之前我遇到过类似的问题。我通过使用'this'调用碰撞函数来修复它。 例如,而不是:
game.physics.arcade.overlap(bullets, goblinSprite, bulletHitEnemy, null, this);
尝试:
game.physics.arcade.overlap(bullets, goblinSprite, this.bulletHitEnemy, null, this);
希望有所帮助。