想要实现一个数字跳动的效果,思路是在间隔内做数字的加减。以前类似在cocos2dx中做过,移植到cocos creator却不行,动画串联完毕后只会执行最后一次的sequence,求指导下面的代码有什么问题吗?
this.ptr_win_lose_label.string = “0.00” ;
let step = userScore>0 ? userScore * 100 : userScore*-1 * 100
let isAdd = userScore > 0 ? 1:(-1)
let once = Math.floor(step/10)+1 //最多跳动50次
once = once > 50 ? 50 : once
let ani = cc.sequence(cc.spawn(cc.scaleTo(1.5,2),cc.fadeIn(1.5)),cc.delayTime(0.01))
var self = this
let index = 0
while(index != userScore){
index = index + once/100 * isAdd;
if(index > userScore ){
index = userScore
}
let setString = cc.callFunc(function(){
if(userScore > 0 ){
self.ptr_win_lose_label.string = “+” + index
}else if(userScore < 0){
self.ptr_win_lose_label.string = “-” + index
}else{
self.ptr_win_lose_label.string = “” + index
}
})
let delay = cc.delayTime(0.015) //间隔0.015秒,
ani = cc.sequence(ani,setString,delay)
}
this.ptr_win_lose_label.node.runAction(ani)
