一、对全部CCActionInterval动作进行加速或减速,这个很简单只要一句代码就可以。
- CCDirector::sharedDirector()->getScheduler()->setTimeScale(2);//以目前2倍速度播放
- CCDirector::sharedDirector()->getScheduler()->setTimeScale(0.5);//以目前0.5倍速度播放
二、对个别单个动作进行加速或减速
有两种方法
1.通过CCSpeed实现
- CCSprite*sprite=CCSprite::create();
- CCActionInterval*jump=CCJumpBy::create(4,ccp(0,0),100,4);
- sprite->runAction(CCSpeed::create(jump,2));//以2倍速度播放动作
2.通过CCActionManager实现,着重讲这个方法
- CCScheduler*scheduler1;
- voidHelloWorld::myInit11()
- {
- CCSizesize=CCDirector::sharedDirector()->getWinSize();
- CCControlSlider*slider1=CCControlSlider::create("sliderTrack.png","sliderProgress.png","sliderThumb.png");
- slider1->setPosition(ccp(size.width/4*2,size.height*0.3));
- this->addChild(slider1);
- slider1->setTag(1);
- //最小值
- slider1->setMinimumValue(0);
- //最大值
- slider1->setMaximumValue(5);
- //回调函数
- slider1->addTargetWithActionForControlEvents(this,cccontrol_selector(HelloWorld::sliderAction),CCControlEventValueChanged);
- //Createanewscheduler,andlinkittothemainscheduler
- scheduler1=newCCScheduler();
- CCDirector::sharedDirector()->getScheduler()->scheduleUpdateForTarget(scheduler1,false);
- //CreateanewActionManager,andlinkittothenewscheudler
- CCActionManager*actionManager1=newCCActionManager();
- scheduler1->scheduleUpdateForTarget(actionManager1,false);
- //左边精灵
- CCActionInterval*jump1=CCJumpBy::create(4,4);
- CCActionInterval*jump2=jump1->reverse();
- CCSequence*seq=CCSequence::create(jump2,jump1,NULL);
- CCRepeatForever*action=CCRepeatForever::create(seq);
- CCSprite*left=CCSprite::create("Icon.png");
- left->setPosition(ccp(size.width/4*1,size.height*0.5));
- this->addChild(left);
- //IMPORTANT:SettheactionManagerrunninganyaction
- left->setActionManager(actionManager1);
- left->runAction(action);
- //中间精灵
- CCSprite*middle=CCSprite::create("Icon.png");
- middle->setPosition(ccp(size.width/4*2,size.height*0.5));
- this->addChild(middle);
- middle->setActionManager(actionManager1);
- middle->runAction(CCRepeatForever::create(CCRotateBy::create(2,360)));
- //右边精灵
- CCSprite*right=CCSprite::create("Icon.png");
- right->setPosition(ccp(size.width/4*3,size.height*0.5));
- this->addChild(right);
- CCActionInterval*scale1=CCScaleBy::create(1,2);
- CCActionInterval*scale2=scale1->reverse();
- CCSequence*seq2=CCSequence::create(scale1,scale2,NULL);
- CCRepeatForever*action2=CCRepeatForever::create(seq2);
- right->setActionManager(actionManager1);
- right->runAction(action2);
- }
- voidHelloWorld::sliderAction(CCObject*pSender,CCControlEventcontrolEvent)
- {
- CCControlSlider*pSliderCtl=(CCControlSlider*)pSender;
- floatvalue=pSliderCtl->getValue();
- scheduler1->setTimeScale(value);
- }
- HelloWorld::~HelloWorld()
- {
- scheduler1->release();
- }