简体   繁体   English

暂停后重新启动THREE.js中的游戏

[英]Restart game in THREE.js after Pausing

I am making a game. 我在做游戏。 I Pause the game by this code in THREE.js 我在THREE.js中通过此代码暂停了游戏

if (keyboard.pressed("E")) {
    animate = false;

 }

if(animate){
requestAnimationFrame(animate);
}

I want to restart the game after pausing, by pressing any other key but don't know how? 我想在暂停后重新启动游戏,方法是按其他任意键,但不知道如何操作? Kindly help me in this regard. 在这方面请帮助我。 Thanks. 谢谢。

You could implement some simple jQuery at the document level to simply do this, 您可以在文档级别实现一些简单的jQuery来完成此操作,

$("body").on("keypress", function (e) {
    if(!animate) animate = true;
});

...thus even if E is pressed again, it will unpause. ...因此,即使再次按E ,它也不会暂停。 This is assuming you are constantly checking animate on an interval. 这是假设您不断检查一个间隔的动画。 Otherwise, you could explicitly make a call to your animate procedure inside of the if qualifier 否则,您可以在if qualifier内显式调用动画过程

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

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