0

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

我试过的方法:

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

  2. 添加包含 setTimeout 函数的 if 语句,为 stopBigWinAnimation 声明布尔类型并添加返回,但是 Uncaught RangeError: Maximum call stack size exceeded

  // 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);

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

4

1 回答 1

1

如果我理解正确,您想在调用 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);

于 2019-08-28T02:24:37.667 回答