前端之家收集整理的这篇文章主要介绍了
cocos2dx 对全部动作或单个动作速度的改变,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
一、对全部CCActionInterval动作进行加速或减速,这个很简单只要一句代码就可以。
- CCDirector::sharedDirector()->getScheduler()->setTimeScale(2);
- CCDirector::sharedDirector()->getScheduler()->setTimeScale(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.通过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);
- scheduler1=newCCScheduler();
- CCDirector::sharedDirector()->getScheduler()->scheduleUpdateForTarget(scheduler1,false);
- 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);
- 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();
- }
原文链接:/cocos2dx/341370.html