CocosCreator关于tween(target).stop在某些场景下失效的解决方案
bug实例:
startani(){
tween(this.grayBg.getComponent(UIOpacity)).repeatForever(
tween().to(0.5,{opacity:150})
.to(0.5,{opacity:255})
.delay(1)
).start();
}
stopAni(){
tween(this.grayBg.getComponent(UIOpacity)).stop();
}
以上没有效果!!! 并不能停止节点运动
API没查到,网上有说没有保存tween的实例,做了一下修改,确实可以停止了。。。那stop的api不是有问题么。而且大部分情况下是有效的啊。
贴一下不生效的解决方案:
startAni(){
this._graybgAni = tween(this.grayBg.getComponent(UIOpacity)).repeatForever(
tween().to(0.5,{opacity:150})
.to(0.5,{opacity:255})
.delay(1)
).start();
}
stopAni(){
if(this._graybgAni)this._graybgAni.stop();
this.grayBg.getComponent(UIOpacity).opacity = 255;
}