javascript - 调用另一个函数时如何禁用该函数?

标签 javascript typescript function spine

我希望在 stop win 功能运行时禁用不透明度淡出功能。我正在使用 typescript 。我怎样才能做到这一点?感谢您的善意帮助。

我尝试过的方法:

  1. 添加包含setTimeout函数的if语句,但显示stopBigWinAnimation类型为void

  2. 添加包含 setTimeout 函数的 if 语句,为 stopBigWinAnimation 声明 Boolean 类型并添加返回值,但 Uncaught RangeError: Maximum call stack sizeangled

  // Stop Win function
  public stopBigWinAnimations() {

      this.mainContainer.opacity = 255

      let animBigWin4 =  this.nodes4.getComponent(sp.Skeleton);
      // Maybe it is not animated or it is the 0th empty node
      if (animBigWin4) {
        animBigWin4.clearTracks();
        animBigWin4.setToSetupPose(); 
        if (animBigWin4.defaultAnimation) {
          animBigWin4.setAnimation(0, animBigWin4.defaultAnimation, true);
        }
      }
    }

    // Fade Out function
    setTimeout(function () {
       this.nodes5.opacity = 0;
       this.nodes6.opacity = 0;
       this.nodes7.opacity = 0;
       this.nodes8.opacity = 0;
    }.bind(this), 6500);

预期结果:停止获胜功能时,淡出功能被禁用。

最佳答案

如果我理解正确,您想在调用 stopBigWinAnimations 时禁用 setTimeout 。

为此,您需要命名 setTimeout (fadeOutFunction),以便您可以在 stopBigWinAnimations 函数运行时“清除”它。

let fadeOutFunction = null;

public stopBigWinAnimations() {
      clearTimeout(fadeOutFunction);

      this.mainContainer.opacity = 255

      let animBigWin4 =  this.nodes4.getComponent(sp.Skeleton);
      // Maybe it is not animated or it is the 0th empty node
      if (animBigWin4) {
        animBigWin4.clearTracks();
        animBigWin4.setToSetupPose(); 
        if (animBigWin4.defaultAnimation) {
          animBigWin4.setAnimation(0, animBigWin4.defaultAnimation, true);
        }
      }
    }

    // Fade Out function
    fadeOutFunction = setTimeout(function () {
       this.nodes5.opacity = 0;
       this.nodes6.opacity = 0;
       this.nodes7.opacity = 0;
       this.nodes8.opacity = 0;
    }.bind(this), 6500);

关于javascript - 调用另一个函数时如何禁用该函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57684050/

相关文章:

javascript - 当点击文本中的某个单词时创建一个弹出框

angular - 引用错误: describe is not defined Karma jasmine angular2

reactjs - 如何生成动态 React 标记

module - 无法从 node_modules typescript 导入 react-tap-event-plugin

javascript - Angular 传递变量

algorithm - Go 程序不显示分配给变量的 Sliced Int 的期望结果

javascript - Angular2 ngFor - 更改项目顺序而不重新创建它们

javascript - 将浏览器位置聚焦在切换 block 上

javascript - 字符映射对象最大值出现次数

php - 是否可以制作一个可以接受任意数量参数的 PHP 函数?