class instance changed in callback method comparing to the main instance


#1

Hi:

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?

Thanks.


#2

I’ve figured this out.

See this link: http://stackoverflow.com/questions/13283247/class-instance-changed-in-callback-method-comparing-to-the-main-instance/13283388#comment18109993_13283388

For more information.

Thanks.