setPosition does not work after applying CCAction

setPosition does not work after applying CCAction
0.0 0



The nodes are in a world with gravity and I updated the Y-axis position in each frame using update scheduler.
In a CCNode, I tried to use CCMoveBy action for nodes to perform movement in X-axis.

Unfortunately, it seems it does not work that the node moves in X-axis only. Is it a normal behavior that once the node is controlled by CCAction, other codes cannot be able to control it correctly? If so, can you give me some idea on how to handle the following? Thanks.
# Nodes inside a world with Gravity
# Nodes inside a world with scroll map (e.g. 2d shooting game)


Cocos2d will calculate the postion before drawing. So the recommended approach is to move the x-axis calculation from CCMoveBy to update scheduler.


For this case, I tried to stick with Action and so I create my own action class which is named as CCTranslate. (I cannot think of other name that is better than “move”).

It simply do the movement and the position is not related to starting point. I put the code here for those who are interested in it.

class CCTranslate : public CCActionInterval
    /** initializes the action */
    bool initWithDuration(ccTime duration, CCPoint position);

    virtual void startWithTarget(CCNode *pTarget);
    virtual void update(ccTime time);

    /** creates the action */
    static CCTranslate* actionWithDuration(ccTime duration, CCPoint position);

    CCPoint m_delta;
    CGFloat m_fLastElapsed;

CCTranslate* CCTranslate::actionWithDuration(cocos2d::ccTime duration, cocos2d::CCPoint position)
    CCTranslate *pMoveTo = new CCTranslate();
    pMoveTo->initWithDuration(duration, position);

    return pMoveTo;

bool CCTranslate::initWithDuration(cocos2d::ccTime duration, cocos2d::CCPoint position)
    if (CCActionInterval::initWithDuration(duration))
        m_fLastElapsed = 0;
        m_delta = position;
        return true;

    return false;

void CCTranslate::startWithTarget(CCNode *pTarget)

void CCTranslate::update(cocos2d::ccTime time)
    cocos2d::ccTime tick = time - m_fLastElapsed;
    if (m_pTarget)
        cocos2d::CCPoint position = m_pTarget->getPosition();
        position.x = position.x + m_delta.x * tick;
        position.y = position.y + m_delta.y * tick;
    m_fLastElapsed = time;


nice, thank you for your share!