当前位置 : 主页 > 手机开发 > harmonyos >

cocos2dx之FadeIn,FadeOut,FadeTo

来源:互联网 收集:自由互联 发布时间:2023-08-25
FadeIn-是从暗逐渐变亮 FadeOut-从亮逐渐变消失。 FadeTo-从亮逐渐变暗 三个类的例子如下: void MyActionFadeLayer::initLayer() { CCSize size = CCDirector::sharedDirector()-getWinSize(); /* *@FadeTo */ CCSprite *spri


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之CCReverseTime
下一篇:没有了
网友评论