cocos2dx之CCTargetedAction

CCTargetedAction,改变当前执行的sprite,例子代码如下:

void MyActionTargetedLayer::initLayer() {
    CCSize size = CCDirector::sharedDirector()->getWinSize();
    CCSprite *sprite = CCSprite::create("blocks.png");
    sprite->setPosition(ccp(100, 500));
    this->addChild(sprite, 1);
    CCActionInterval *forward = CCSkewBy::create(4, 40, 40);


    CCSprite *spriteJump = CCSprite::create("r1.png");
    spriteJump->setPosition(ccp(100, 500));
    this->addChild(spriteJump, 1);
    CCActionInterval *forwardJump = CCJumpBy::create(4, ccp(200, 100), 100, 10);
    CCTargetedAction *t1 = CCTargetedAction::create(spriteJump, forwardJump);
    CCAction *action = CCSequence::create(forward, t1, forward->reverse(), NULL);

    sprite->runAction(action);
}

首先执行sprite中的forward,然后执行的是spriteJum这个sprite(因为利用CCTargetedAction改变了当前sprite),最后执行的sprite的forward->reverse()行为。

你可能感兴趣的:(cocos2dx学习)