3
votes

allyMonser is a CCSprite (Inheritance). When I use schedule, allyMonster is NULL in action(). But, When I call action() directly, allyMonster is Not NULL, it is normal.

When I run this code, the log shows:

1, 0x23ds566
2, 0xfffffff

I want know the reason 1, 0x23ds566 -> 2, 0xfffffff. Why does it change?

void AMS_Moving::runAction()
{
    allyMonster->unscheduleAllSelectors();
    allyMonster->stopAllActions();
    allyMonster->schedule( schedule_selector( AMS_Moving::action ) );

    CCLog("1. %x", allyMonster);
}

void AMS_Moving::action()
{
    CCLog("2. %x", allyMonster);
    ...
    ...
}
1

1 Answers

0
votes

I guess the reason is, when you run the scheduled function, it is not pointing to the function you want, but something else, because

void AMS_Moving::action() 

is wrong. by default, all schedule function should take an input ccTime dt, which should be

void AMS_Moving::action(ccTime dt)