我正在使用以下代码(这是一个简化的代码片段,以便使其更具可读性):
var player;
var box_tnt;
function create (){
this.physics.add.collider(player, box_tnt, hitTnt, null, this);
}
//the function hitTnt stop the game because the player died
function hitTnt (player, boxes){
this.physics.pause();
player.setTint(0xff0000);
player.anims.play('default');
gameOver = true;
textGameOver.setText('GAME OVER');
}
- 实际表现:
当玩家击中炸弹时:玩家死亡;游戏结束
- 期望的行为举止:
当玩家击中炸弹时:炸弹等待3秒然后爆炸!如果玩家距离太近,他就会死亡。 但即使在阅读了论坛上的很多示例之后,我仍然很难使用计时器。我是 Phaser 的新手,所以到目前为止我还没有成功。
如有任何帮助,我们将不胜感激,预先感谢您!
最佳答案
假设您使用的是 Phaser 3,这些是您可以使用计时器的方法。
- delayedCall 方法,较短。
delayedCall(延迟、回调、args、callbackScope)
所以,你会做这样的事情。
this.time.delayedCall(2000, onEvent, null, this);
- addEvent 方法
addEvent(config)
Docs for config
this.time.addEvent({ 延迟:2000,回调:onEvent,callbackScope:this });
在文档中查找这些方法 here .
查找计时器事件的示例 here .
<小时/>您可以做的其他事情是,如果您有任何播放 3 秒的补间(如果您正在补间炸弹或为其设置动画 3 秒)。您可以将 onComplete
回调附加到它。因此,在 Tween 结束后,onComplete
回调将被执行。
关于javascript - 移相器 : How to use a simple timer from 0 to 3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54630495/