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

前端之家收集整理的这篇文章主要介绍了cocos2d-x学习笔记(10)重复动作RepeatForever和Repeat 以及动作组合Sequence和Spawn前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

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,1);

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

	JumpBy* jumpBy=JumpBy::create(3.0f,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是动作一起执行。

猜你在找的Cocos2d-x相关文章