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

本文探讨了游戏开发中动作执行的关键技术,包括重复动作、序列执行和动作组合使用,详细介绍了如何通过Action、Sequence和Spawn等动作实现复杂的动画效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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是动作一起执行。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值