1
votes

In my C++/Cocos2d-x code I have some custom Cocos2d actions; in my case, classes inheriting CCActionInterval or CCActionInstant. I notice a difference between Cocos2d-x version 1.0.1 and version 2.0 in how update methods of these classes are called . Before the upgrade, the update methods were always called at least once with time=1.0. From what I see now, in version 2.0, the update method of the instant actions is called only once with time=0. Is it always so? Can I assume that, in version 2.0, in classes inheriting CCActionInstant, the update method will be called only once and the time value will always be zero?

1

1 Answers

0
votes

I'll say this first, I don't think you should be worrying about such implementation detail. When you subclass CCActionInstant, you can always assume that your subclass is an instant action. If the implementation details changed in the future, they'll probably be made to make the class even better, and your subclass should perform better.

With that being said, you might have your reason to worry about this implementation detail, so, here is an extended answer.

You can assume it is always called at time 0 as long as you don't update your library. Cocos2d-x is very dynamic, and changing according to the cocos2d-iphone version, so changes are bound to happen.


In cocos2d v2.0, all actions are managed by the CCActionManager class. So, by checking that class, you can see:

// main loop
void CCActionManager::update(float dt)
{
...
    if (m_pCurrentTarget->currentAction->isDone())
    {
        m_pCurrentTarget->currentAction->stop();

        CCAction *pAction = m_pCurrentTarget->currentAction;
        // Make currentAction nil to prevent removeAction from salvaging it.
        m_pCurrentTarget->currentAction = NULL;
        removeAction(pAction);
    }
}

As you can see, removeAction is called when the isDone() is true. Not surprisingly, the isDone() method in CCActionInstant always returns true, hence always gets removed after excuting once :).