我希望在 stop win 功能运行时禁用不透明度淡出功能。我正在使用 typescript 。我怎样才能做到这一点?感谢您的善意帮助。
我尝试过的方法:
添加包含setTimeout函数的if语句,但显示stopBigWinAnimation类型为void
添加包含 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/