简体   繁体   English

如何不增加功能延迟

[英]How to not add a delay to a function

I am new to JavaScript and following this tutorial I have made the game work perfectly and it goes up to the part of were the the level changes when you destroy all the objects. 我是JavaScript的新手 ,在学习了本教程之后,我已经使游戏完美运行,并且在破坏所有对象时,级别发生了变化。 However as I am learning I am trying to figure out how to make it so that it changes level without a delay. 但是,在我学习的过程中,我试图弄清楚如何制作它,以使它的电平立即变化。

The main part of the bit which switches level is : 切换电平的位的主要部分是:

if (!this.rockmodel.countLiving()) {
    Asteroid.time.events.add(Phaser.Timer.SECOND * gameWindow.delayToStartLevel, this.levelIncrease, this);
}

However if I take out the delayToStartLevel bit, it does not switch level. 但是,如果我取出了delayToStartLevel位,则它不会切换电平。 So I tried to make it looks like this: 所以我试图使它看起来像这样:

Asteroid.time.events.add(this.levelIncrease, this);

But the next level does not show at all. 但是下一个级别根本不显示。 Not sure if I am being an idiot etc, but any help on this matter would be great. 不知道我是否是个白痴,但是在这个问题上的任何帮助都会很棒。

Again just to make some sense, it works fine with the delay, I want to get rid of that function completely but its not working at all. 再说一次,从某种意义上讲,它在延迟方面可以正常工作,我想完全摆脱该功能,但根本无法使用。

Thanks. 谢谢。

The time.events.add will add an event to the Phaser game object. time.events.add将事件添加到Phaser游戏对象。 In other words it will fire the given function after X milliseconds. 换句话说,它将在X毫秒后触发给定的函数。

If you do not want a delay then you can just call the function directly, instead of postponing the function call. 如果您不希望延迟,则可以直接调用该函数,而不必推迟该函数的调用。 Something like this: 像这样:

if (!this.rockmodel.countLiving()) {
    this.levelIncrease();
}

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

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