Cocos2d-x动画加速与减速
来源:互联网 发布:java thread local 编辑:程序博客网 时间:2024/06/10 16:38
1)实现全局的加速、减速。
通过设置Scheduler的timeScale,可以实现全局的加、减速。代码非常简单:
CCScheduler* pScheduler = CCDirector::sharedDirector()->getScheduler();
pScheduler->setTimeScale(2.0f); //实现加速效果
pScheduler->setTimeScale(0.5f);//实现减速效果
2)实现对某个CCActionInterval动作的加速、减速
方法一:很容易想到的一个方法就是改变CCAnimation的delay unit。代码如下:
CCAnimation* pAnimation = CCAnimationCache::sharedAnimationCache()->animationByName(“xxx”);
pAnimation->setDelayUnit(pAnimation->getDelayUnit()*0.2f); //速度为原来的5倍
这个方法有一个缺点:改变了CCAnimationCache中这个animation的delay unit。也就是说以后即使再从CCAnimationCache中获取这个animation,其delay unit已经是原来的0.2倍了。
方法二:cocos2d-x提供了CCSpeed的类,可以实现动画速度的调节。用法如下:
CCActionInterval* pActionInterval = CCMoveTo::create(5.0f, ccp(500.0f, 100.0f));
CCSpeed* pSpeed= CCSpeed::create(pActionInterval, 1.5f); //1.5倍速运行
CCSpeed* pSpeed1 = CCSpeed::create(pActionInterval, 0.2f);// 0.2倍速运行
pSprite->runAction(pSpeed);
注意,如果pSprite有已经运行的动作,要用pSprite->stopActionByTag()停掉之前的动作,不然两个动作就叠加到一起了。
3)对某个CCFiniteTimeAction类型动作的加速、减速
大部分时候,一个游戏人物的动作并非由单一一个CCActionInterval类型的动作构成,而是一串动作连起来,构成一个Sequence。用CCSequence::create(…)创建的对象都是CCFinteTimeAction类型的,CCSpeed并不适用。在CCSpeed类的说明里,明确指出”This action can’t be Sequenceable because it is not an CCIntervalAction”。那对于Sequence就束手无策了吗?非也。cocos2d-x引擎自带例子中,schedulerTest给我们展示了如何控制某个sprite的scheduler的timescale。废话少说,直接看代码。
在class TwoSchedulers中定义了两个customer的scheduler和两个CCActionManager。
CCScheduler *sched1;
CCScheduler *sched2;
CCActionManager *actionManager1;
CCActionManager *actionManager2;
在onEnter函数中,分别对两个sprite设置customer的ActionManager.
CCScheduler *defaultScheduler = CCDirector::sharedDirector()->getScheduler();
// Create a new scheduler, and link it to the main scheduler
sched1 = new CCScheduler();
defaultScheduler->scheduleUpdateForTarget(sched1, 0, false);
// Create a new ActionManager, and link it to the new scheudler
actionManager1 = new CCActionManager();
sched1->scheduleUpdateForTarget(actionManager1, 0, false);
// Replace the default ActionManager with the new one.
pSprite1->setActionManager(actionManager1);
通过以上的代码,就可以通过改变sched1的timescale来改变pSprite1的动作的快慢了。有了这种方法,那么就可以放弃CCSpeed的那种方法了。
- Cocos2d-x动画加速与减速
- cocos2d-x动画加速与减速
- cocos2d-x动画加速与减速
- cocos2d-x 动画加速与减速
- cocos2d-x动画加速与减速
- cocos2d-x 动画加速与减速
- cocos2d-x 动画加速与减速
- cocos2d-x 动画加速与减速
- cocos2d-x动画加速与减速(转)
- cocos2d-x动画加速与减速(转载)
- cocos2d-x动画加速与减速(转载)
- cocos2dx动画加速与减速
- cocos2d - x easing 减速
- 加速,减速..............
- cocos2d-x 动作与动画
- View中使用Interpolator实现先加速后减速动画
- 围绕中心匀速,加速,减速转动的动画
- 四.cocos2d-x中的动画与动作
- java new Date 获取时间 与系统不一致
- A communication class for serial port
- myeclipse集成ant
- 将java console的输出写入文件
- Android Manifest之<action>元素中文注释
- Cocos2d-x动画加速与减速
- linux查找目录下的所有文件中是否含有某个字符串
- LoadRunner,是一种预测系统行为和性能的负载测试工具
- 解决Tomcat - which must be escaped when used within the value错误
- android布局属性使用说明和一些开发经验
- oracle 11g 从11.2.0.3.0升级到11.2.0.3.6操作步骤(一)
- java.lang.OutOfMemoryError: PermGen space及其解决方法
- 关于多态(polymorphism)的初步知识(此处指动态多态)
- android短信和广播机制