2.4的代码:
public playAddAnima(value: number) {
this.node.getComponent(cc.Label).string = "+" + value;
cc.Tween.stopAllByTarget(this.node);
this.node.opacity = 100;
this.node.scale = 0.5;
this.node.y = 0
cc.tween(this.node)
.to(0.2, { opacity: 255, scale: 1.2, y: 30 })
.delay(0.2)
.to(0.1, { opacity: 0 })
.call(() => {
this.node.destroy();
})
.start()
}
3.5的代码
public playAddAnima(value:number){
this.node.getComponent(Label).string = "+" + value;
Tween.stopAllByTarget(this.node);
//透明度
this.node.getComponent(UIOpacity).opacity = 100;
//放缩
this.node.setScale(0.5,0.5,0.5);
this.node.setPosition(0,0,0);
tween(this.node)
.to(0.2,{scale:new Vec3(1.2,1.2,1.2)})
.call(()=>{
const opacityCommponent = this.node.getComponent(UIOpacityComponent);
if(opacityCommponent){
opacityCommponent.opacity = 255;
}
})
.to(0.2,{position:new Vec3(this.node.position.x,this.node.position.y+30,this.node.position.z)})
.delay(0.2)
.call(()=>{
const opacityCommponent = this.node.getComponent(UIOpacityComponent);
if(opacityCommponent){
opacityCommponent.opacity = 0;
}
})
.call(()=>{
this.node.destroy();
})
.start();
}
两段代码表现是否相同,是否有可以优化的空间?
