Problem in cc.Sequence with cc.DelayTime +cc.CallFunc?

Hello

i’m trying to highlight a cc.LabelTFF with the following code:


label.runAction(cc.Sequence.create(cc.DelayTime.create(2),cc.CallFunc.create(this.setLabelColor(label),this))); // label is declared previously
————
setLabelColor:function(label) {
label.setColor(cc.c3b(38, 59, 152));
}

the labels is instantaneous colored. the delayTime seems not to work.
i using the last version of cocos2d-html5.
i know that i have other ways to resolve it but i want know why this not work.

Thanks!.

You have to pass to cc.CallFunc a reference to the function to call, what you are doing with “this.setLabelColor(label)” is calling setLabelColor and sending cc.CallFunc the result of that function.
One option is to use cc.CallFunc third parameter to pass a reference to the label:

`label.runAction(cc.Sequence.create(cc.DelayTime.create(2),cc.CallFunc.create(this.setLabelColor, this, label)));

setLabelColor:function(target, label) {
label.setColor(cc.c3b(38, 59, 152));
}`

Note that when creating the cc.CallFunc object, I’ve used this.setLabelColor (the reference to the function) and not *this.setLabelColor(label)* (function invocation).

1 Like

Thank you very much,

you resolved my doubt!

i did changes respect your code:

this.labels[i].runAction(
cc.Sequence.create(
cc.DelayTime.create(2),
cc.CallFunc.create(function(node) {
node.setColor(highlightColor);
}, this),
));

thanks