in cpp:
void Character::jump(CCLayer *layer){
if (this->isAnimationPlaying) return;
up_or_down = UP;
body->runAction(CCSequence::actions(
CCMoveBy::actionWithDuration(0.5, ccp(0, 50)),
CCCallFuncND::actionWithTarget(body, callfuncND_selector(Character::upDownDone), this),
// CCCallFuncN::actionWithTarget(body, callfuncN_selector(Character::upDownDone)),
NULL));
this->isAnimationPlaying = true;
}
void Character::upDownDone(CCNode *node, CCObject *ob){
this->isAnimationPlaying = false; // *this is different from the this(class instance) in jump method, seems this in upDownDone is a new created instance*
}
So How can I get the class instance in a callback method? And can I make the this same for the main class instance and the callback’s class instance?
EDIT:
Character is a class which has no parent class, and body is a member variable which is an instance of CCSprite.
Thanks.
because you are using
bodyto call the functionCharacter::upDownDone.you should use
thisto call it.assume your
secend_argiscallfuncND_selector(Character::upDownDone)then,
the
first_argis the caller, ie. the class instance who calls this function, in your code isbody. but actually it should bethis, or any instance of Charactor classthe
CCNode* node(the first para that is been passed to your calling function) is the action runner, ie.bodyin your code. because you are usingbody->runAction()the
CCObject* obj(the second para that is been passed to your calling function) is a void pointer which is exactly the same withthird_arg.another way is use