您的位置:首页 > 移动开发 > Cocos引擎

cocos2d-x学习笔记(10)重复动作RepeatForever和Repeat 以及动作组合Sequence和Spawn

2015-12-12 21:10 591 查看
Repeat和RepeatForever

Sprite* sprite=Sprite::create("sprite.png");
sprite->setPosition(Point(visibleSize.width/2,visibleSize.height/2));
this->addChild(sprite,1);

JumpBy* jumpBy=JumpBy::create(3.0f,Point(50,1),100,1);

//RepeatForever* repeatforeverAction=RepeatForever::create(jumpBy);

Repeat* repeatAction=Repeat::create(jumpBy,3);

sprite->runAction(repeatAction);


Sequence和Spawn

Sprite* sprite=Sprite::create("sprite.png");
sprite->setPosition(Point(visibleSize.width/2,visibleSize.height/2));
this->addChild(sprite,1);

MoveBy* moveBy=MoveBy::create(2.2f,Point(40,20));

JumpBy* jumpBy=JumpBy::create(3.0f,Point(50,1),100,5);

RotateBy* rotateBy=RotateBy::create(2.5f,220,10);

Action* action=Spawn::create(moveBy,jumpBy,rotateBy,NULL);

sprite->runAction(action);

Action是所有动作额父类,Spawn也是一个动作,只不过这个动作又可以包含若干个动作,最后一个参数是NULL值,因为Spawn的create函数参数是可变参数,需要用NULL值表示结束。.

Seqence是动作一个接着一个执行;

Spawn是动作一起执行。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: