如何在调用另一个函数时禁用函数?

How to disable function when another function is called?

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

我试过的方法:

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

  2. 添加包含setTimeout函数的if语句,为stopBigWinAnimation声明布尔类型并添加一个return,但是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);

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

如果我没理解错的话,您想在调用 stopBigWinAnimations 时禁用 setTimeout。

为此,您需要命名 setTimeout (fadeOutFunction),这样您就可以在 stopBigWinAnimations 函数运行时"clear"它。

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