cocos2dx 모든 동작 또는 단일 동작 속도 변경

3592 단어


평론과 관심에 감사드리며, 전재와 공유를 환영합니다.부지런히 노력하여 꾸준하게 견지하라!


1. 모든 CCActionInterval 동작을 가속하거나 감속시킨다. 이것은 코드 한 마디만 있으면 된다.

CCDirector::sharedDirector()->getScheduler()->setTimeScale(2);//   2     
    CCDirector::sharedDirector()->getScheduler()->setTimeScale(0.5);//   0.5     

2. 개별 개별 동작에 대해 가속 또는 감속


두 가지 방법이 있어요.


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;
void HelloWorld::myInit11()
{
    CCSize size = 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);
    
    
    // Create a new scheduler, and link it to the main scheduler
    scheduler1 = new CCScheduler();
    CCDirector::sharedDirector()->getScheduler()->scheduleUpdateForTarget(scheduler1, 0, false);
    
    // Create a new ActionManager, and link it to the new scheudler
    CCActionManager* actionManager1 = new CCActionManager();
    scheduler1->scheduleUpdateForTarget(actionManager1, 0, false);
    
    
    //    
    CCActionInterval *jump1 = CCJumpBy::create(4, ccp(0,0), 100, 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: Set the actionManager running any action
    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);
}

void HelloWorld::sliderAction(CCObject* pSender, CCControlEvent controlEvent)
{
    CCControlSlider* pSliderCtl = (CCControlSlider*)pSender;
    float value = pSliderCtl->getValue();
    
    scheduler1->setTimeScale(value);
}

HelloWorld::~HelloWorld()
{
    scheduler1->release();
}

좋은 웹페이지 즐겨찾기