可以将以系统动作 连接起来 一起实现,这个就要靠 CCAction 家族的 CCSpawn(CCSequence) 方法了,这也是一个动作 只是将以系统组合起来了 CCspawn的create函数是参数是可变的,所以传完我们需要的参数后,记得 再传一个 NULL 标记传参结束。下面看看例子:
bool Sequence::init(void){
bool bRet = false;
do
{
CC_BREAK_IF(! CCLayer::init());
CCSize layerSize = CCDirector::sharedDirector() ->getVisibleSize();
CCSprite* sprite = CCSprite::create("sprite.png");
CC_BREAK_IF(! sprite);
sprite ->setAnchorPoint(ccp(0,0));
sprite ->setPosition(ccp(layerSize.width / 2, layerSize.height / 2));
this ->addChild(sprite);
// 创建移动动作对象
CCMoveTo* moveTo = CCMoveTo::create(3.0f, ccp(0,0));
CC_BREAK_IF(! moveTo);
// 创建弹跳动作对象
CCJumpBy* jumpBy = CCJumpBy::create(3.0f,ccp(50,1), 100, 5);
CC_BREAK_IF(! jumpBy);
//创建旋转对象
CCRotateBy* rotate = CCRotateBy::create(2.5f, 200, 10);
CC_BREAK_IF(! rotate);
//创建动作组合对象 将所有的动作连接起来
//CCAction* actions = CCSpawn::create(moveTo, jumpBy, rotate, NULL); // 一起播放
CCAction* actions = CCSequence::create(moveTo, jumpBy, rotate, NULL);//一个一个动作播放
CC_BREAK_IF(! actions);
sprite ->runAction(actions);
bRet = true;
} while (0);
return bRet;
}