Fade in/out effect

I want to show/hide a CCLayer with fade in/out effects when i try with the method below nothing happens. (cocos2d-x version 2.2.2)

void MainScene::setMenuVisibility(bool value)
{
    if(value)
    {
        CCFadeIn* fadeIn = CCFadeIn::create(5);

        mainMenuLayer->runAction(fadeIn);
    }
    else
    {
        CCFadeOut* fadeOut = CCFadeOut::create(5);

        mainMenuLayer->runAction(fadeOut);
    }
}

Before FadeIn/Out you have to setOpacity(0) or setOpacity(255). Don’t setVisible(false).

1 Like

Thanks for your help but i can’t find the setOpacity method

Layer class seem don’t have setOpacity method, but Sprite has: http://www.cocos2d-x.org/reference/native-cpp/V2.2.2/d8/de9/group__sprite__nodes.html#ga7f9374d8fd4db565312b125795a877ff
Maybe it help.

try CCLayerColor

You cannot use CCFadeIn/CCFadeOut on CCLayer , because we cannot manipulate the opacity of CCLayer (thats y it does not have any setOpacity() method). But if you want to use those actions you can use CCLayerColor instead.