各位好, 原本有一個簡單的跑馬燈 想要改寫成TweenAction 卻一直出現問題:
var len = list.length-1;
this.node.getChildByName("marquee").getChildByName("mask").getChildByName("label").getComponent(cc.Label).string = list[len].title+': '+list[len].text;
var txt = this.node.getChildByName("marquee").getChildByName("mask").getChildByName("label");
this.defaultPos = txt.x;
var action = cc.moveTo((txt.width/200), cc.v2((txt.x - (txt.width + txt.width/2)), txt.y));
var reset = cc.callFunc(function() {
txt.x = this.defaultPos; // reset where txt was
len --;
this.node.getChildByName("marquee").getChildByName("mask").getChildByName("label").getComponent(cc.Label).string = list[len].title+': '+list[len].text;
if(len < 1){
len = list.length;
}
},this);
var seq = cc.repeatForever(cc.sequence(action, cc.delayTime(0.5) ,reset));
txt.runAction(seq);
這是改寫後的
var len = list.length-1;
this.node.getChildByName("marquee").getChildByName("mask").getChildByName("label").getComponent(cc.Label).string = list[len].title+': '+list[len].text;
var txt = this.node.getChildByName("marquee").getChildByName("mask").getChildByName("label");
this.defaultPos = txt.x;
let action = cc.tween().to((txt.width/200), cc.v2((txt.x - (txt.width + txt.width/2)), txt.y));
var reset = cc.callFunc(function() {
txt.x = this.defaultPos;
len --;
this.node.getChildByName("marquee").getChildByName("mask").getChildByName("label").getComponent(cc.Label).string = list[len].title+': '+list[len].text;
if(len < 1){
len = list.length;
}
},this);
cc.tween(txt)
.repeat(
cc.tween().then(action)
.delay(0.5)
.then(reset);
)
.start()
請問哪邊寫錯了呢? 謝謝
