cocos2dx之FadeIn,FadeOut,FadeTo

FadeIn->是从暗逐渐变亮

FadeOut->从亮逐渐变消失。

FadeTo->从亮逐渐变暗

三个类的例子如下:

void MyActionFadeLayer::initLayer() {
    CCSize size = CCDirector::sharedDirector()->getWinSize();
    /*
    *@FadeTo
    */
    CCSprite *spriteFadeTo = CCSprite::create("r1.png");
    spriteFadeTo->setPosition(ccp(size.width / 2.0f, size.height / 2.0f));
    this->addChild(spriteFadeTo, 1);

    CCActionInterval *forwardTo = CCFadeTo::create(5, 20);
    spriteFadeTo->runAction(forwardTo);


    /*
    *@FadeIn
    */
    CCSprite *spriteFadeIn = CCSprite::create("snow.png");
    spriteFadeIn->setPosition(ccp(600, 400));
    this->addChild(spriteFadeIn, 1);
    CCActionInterval *forwardIn = CCFadeIn::create(5);
    CCActionInterval *backIn = forwardIn->reverse();
    CCAction *actionIn = CCSequence::create(forwardIn, backIn, NULL); // 由暗变亮,然后再变暗,因为用了backIn
    spriteFadeIn->runAction(actionIn);

    /*
    *@Fade Out
    */
    CCSprite *spriteFadeOut = CCSprite::create("snow.png");
    spriteFadeOut->setPosition(ccp(300, 400));
    this->addChild(spriteFadeOut, 1);
    CCActionInterval *forwardOut = CCFadeOut::create(2.0f);
    CCActionInterval *backOut = forwardOut->reverse();
    CCAction *actionOut = CCSequence::create(forwardOut, backOut, NULL); //  
    spriteFadeOut->runAction(forwardOut);

}



 

你可能感兴趣的:(cocos2dx之FadeIn,FadeOut,FadeTo)