Cocos2d-x动作组合

Cocos2d-x动作组合:有四种组合方式: 1、CCSequence按顺序执行, 2、CCRepeat重复几次, 3、CCRepeatForever永远重复 4、CCSpawn同时执行





首先,我们先在bool HelloWorld::init()方法中添加如下代码:

添加精灵和动作

CCSprite* player = CCSprite::create("Icon.png"); player->setPosition(ccp(100, 100)); this->addChild(player); CCMoveTo* move = CCMoveTo::create(2, ccp(200, 200)); CCMoveBy* moveBy = CCMoveBy::create(2, ccp(-100, 0)); CCRotateBy* rotate = CCRotateBy::create(2.0, 720);


以下是实现动作组合的代码:


//CCSequence按顺序执行先执行move,再执行moveByCCFiniteTimeAction* seq = CCSequence::create(move,moveBy,NULL);player->runAction(seq);




//CCRepeat重复几次 CCRepeat* rep= CCRepeat::create(rotate, 3);player->runAction(rep);



//这个同时执行的方法大家要注意一点如果在create(move,rotate,moveBy,NULL)方法中先写moveTo之后再写moveBy 就像前面的方法那样 ,moveTo的方法会被忽略CCFiniteTimeAction* span = CCSpawn::create(move,rotate,moveBy,NULL);player->runAction(span);


// CCRepeatForever永远执行 CCRepeatForever* reF = CCRepeatForever::create(rotate); player->runAction(reF);


代码下载: http://pan.baidu.com/share/link?shareid=419310546&uk=3189484501