CCTargetedAction

改变动作执行对象CCTargetedAction

通常默认的动作执行对象是调用runAction的对象,而CCTargetedAction可以改变动作执行对象。

CCTargetedAction* t = CCTargetedAction::create(sprite2, moveto);

sprite->runAction(CCSequence::create(moveto, t, moveto, NULL));

sprite先moveto,然后sprite2执行moveto,最后sprite执行moveto。

void ActionTargeted::onEnter()
{
    ActionsDemo::onEnter();
    centerSprites(2);


    CCJumpBy* jump1 = CCJumpBy::create(2,CCPointZero,100,3);
    CCJumpBy* jump2 = (CCJumpBy*)jump1->copy()->autorelease();
    CCRotateBy* rot1 =  CCRotateBy::create(1, 360);
    CCRotateBy* rot2 = (CCRotateBy*)rot1->copy()->autorelease();

    CCTargetedAction *t1 = CCTargetedAction::create(m_kathia, jump2);
    CCTargetedAction *t2 = CCTargetedAction::create(m_kathia, rot2);

    //首先m_tamara执行jump1动作,然后m_kathia执行jump2动作,m_tamara执行rot1动作,然后m_kathia执行rot2动作
   //以上一组动作重复循环
    CCSequence* seq = (CCSequence*)CCSequence::create(jump1, t1, rot1, t2, NULL);
    CCRepeatForever *always = CCRepeatForever::create(seq);

    m_tamara->runAction(always);
}

 

你可能感兴趣的:(action)