CCTransition with the same scene


#1

Is it possible to imitate a transition (CCTransitionPageTurn) with the same scene? For example there is a scene that is changing and I want to make a transition between its previous and new state.


#2

the easiest way if you only want fadein fadeout transitions would be to place a large sprite on the top layer of your game and gradually change its opacity with .setOpacity(), if you want to make the more fancy transition then i would probably do an init with the states for example:

bool HelloWorld::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !CCLayer::init() )
    {
        return false;
    }
        state = CCUserDefault::sharedUserDefault()->getIntegerForKey("state");
        switch(state)
        {
         case 1:
         //state 1
         break;
         case 2:
         //state 2
         break;
        }
}
//when you want to replace the scene 
CCUserDefault::sharedUserDefault()->setIntegerForKey("state",++state);
CCScene *sameScene;
sameScene = Splash::scene();
CCDirector::sharedDirector()->replaceScene(ZoomFlipXLeftOver::transitionWithDuration(1.0f, sameScene));

note that i haven’t tested this, just what i would do to achieve something like this, there might be an easier way tho.


#3

I think about a different approach. What if to take a snapshot of the current scene and to replace the scene with its own snapshot? The only problem - how to make a snapshot?


#4

i just took a look at CCTransition.cpp and fade transitions are new layers and camera movements for flip transitions, so you should be able to replicate them easily in your scene without replacing the scene.


#5

To be honest, I don’t understand what you mean :frowning:


#6

try this->runAction(CCOrbitCamera::actionWithDuration(1.0f, 1, 0, 270, 90, 90, 0)); in your scene :wink:


#7

Thank you! That is exactly what I want.