我正在使用 Phaser.io我刚刚学会了如何设置碰撞器功能:this.physics.add.collider(enemies, platforms, function (enemy) { enemy.destroy(); gameState.score += 10;});但我想在没有平台的情况下做同样的事情。我想使用世界边界而不是平台。我知道你可以像这样设置世界边界:player.setCollideWorldBounds(true);我试过了:this.physics.add.collider(enemies, this.worldBounds, function (enemy) { enemy.destroy(); gameState.score += 10;});但这不起作用。有任何想法吗?
1 回答
红糖糍粑
TA贡献1815条经验 获得超6个赞
我为您找到了解决方案:
首先,将敌人的精灵设置为与setCollideWorldBounds(true)碰撞,如下所示:
enemy.setCollideWorldBounds(true);
其次,打开敌人精灵的选项来监听WorldBound 事件,如下所示:
enemy.body.onWorldBounds = true;
第三次和最后一次,设置“wordbounds”事件侦听器并使敌人像这样消失:
enemy.body.world.on('worldbounds', function(body) {
// Checks if it's the sprite that you'listening for
if (body.gameObject === this) {
// Make the enemy sprite unactived & make it disappear
this.setActive(false);
this.setVisible(false);
}
}, enemy);
添加回答
举报
0/150
提交
取消