cocos2d, can we call a function in "sequence" on a sprite?

184 Views Asked by At

first I am moving the sprite from a to b. when it reaches b, I need to call a function to work on the sprite, i.e fade, change image etc. I am currently doing it with a "sequence".

var seq_action = cc.Sequence.create(move_action, this.check_basket_under());

But it gives me this error -

CCActionInterval.js:507 Uncaught TypeError: Cannot read property '_timesForRepeat' of undefined
    at Function.cc.sequence [as create] (CCActionInterval.js:507)
    at Class.sprite_create (app.js:110)
    at Class.trigger (CCScheduler.js:261)
    at Class.update (CCScheduler.js:167)
    at Class.update (CCScheduler.js:480)
    at Class.drawScene (CCDirector.js:226)
    at Class.mainLoop (CCDirector.js:884)
    at callback (CCBoot.js:2160)
1

There are 1 best solutions below

0
Guru On

In Sequence, you can't directly call function. Add callFunc or callBlock

Here is c++ version example:

auto scale = EaseElasticOut::create(ScaleTo::create(3.0f, 1.0f));
auto calb = CallFunc::create( [this] () {
    this->check_basket_under( );
});
auto seq = Sequence::create(scale, calb, NULL);

GameOverLabel->runAction(seq);

For more info google CallFunc, CallFuncN usage in Sequence.