简体   繁体   English

JavaScript Phaser游戏中的计时器

[英]Timer in javascript phaser game

I am trying to create a timer to limit the amount of time a player can use their jetpack in my phaser game. 我正在尝试创建一个计时器,以限制玩家在我的相位游戏中可以使用其喷气背包的时间。 I've been following this( http://www.joshmorony.com/how-to-create-an-accurate-timer-for-phaser-games/ ) but I can't get anything to work. 我一直在关注此内容( http://www.joshmorony.com/how-to-create-an-accurate-timer-for-phaser-games/ ),但是我什么也无法工作。 Is there a better way to implement this? 有没有更好的方法来实现这一目标?

var use_jetpack;  

jetpack_timer = game.time.events.add(
    Phaser.Timer.SECOND * 1 /*change the 1 to however many seconds you want*/,
    end_jetpack /*runs the function end_jetpack*/,
    this);

function end_jetpack(){
    use_jetpack = false;
    //if you want a cool down, put it here. follow what was done in line 3.
}

if(use_jetpack){
   //player can use jetpack
}else{
   //player cannot use jetpack
}

Try this. 尝试这个。 I don't know what you couldn't get to work, but this is what my implementation would be. 我不知道您无法上班,但这就是我的实现。 Of course you would need to put functions in update(), and the variable wherever you put those. 当然,您需要将函数放在update()中,并将变量放在任何位置。 This is just a quick demo. 这只是一个快速演示。 Also I had odd formatting for teaching purposes. 我也出于教学目的使用了奇数格式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM