0
  this.update = function() {
    if (state == "game") {
      if (jaws.pressed("p") && !jaws.paused) {
        jaws.paused = true;
        setTimeout(function() {
          var unpause_interval_id = setInterval(function() {
            if (jaws.pressed("p") && jaws.paused) {
              jaws.paused = false;
              clearInterval(unpause_interval_id);
            }
          });
        }, 5000);
      }

那是我尝试暂停我正在开发的游戏。基本上,当播放器暂停时,我将 5 秒的超时设置为检查播放器是否要取消暂停的函数。

但是,我没有成功清除间隔, clearInterval 函数不起作用,我从我调试的内容中确定。知道我做错了什么吗?

谢谢!

4

2 回答 2

2

怎么样:

function p_unp()
{
   jaws.paused = !jaws.paused;
}

jaws.on_keypress("p", p_unp);
于 2012-04-07T12:20:30.940 回答
-3

我建议删除setInterval功能。while loop相反:

  this.update = function() {
    if (state == "game") {
      if (jaws.pressed("p") && !jaws.paused) {
        jaws.paused = true;
        while (jaws.paused) {
            if (jaws.pressed("p") && jaws.paused) {
              jaws.paused = false;
            }
        }
    });
  }
于 2012-04-07T12:14:01.343 回答