Question

I have one CCScene, in which their is About us ICON. When I tap on it, goes to the next CCScene where the information to display.

Now, what happen

When I touch on the back option of the android phone, Game closed.

what I need

when I click the back, It takes me to the First CCscene, where the Icon of ABOUT us present.

What should I do for this ???

Solution : From what I solve

CCDirector.sharedDirector().popScene();
Was it helpful?

Solution

You can use the CCDirector to push scenes on top of running scenes. Say you have scene1 and scene2 both instances of CCScene (or a subclass of CCScene) then when the user taps the about icon :

[[CCDirector sharedDirector] pushScene:scene2]; // Assuming scene1 is already running

when the user taps the back button :

[[CCDirector sharedDirector] popScene];

EDIT : According to your comment (and in java this time :)) :

public void onBackPressed() { 
   super.onBackPressed(); 
   if(backPressFlag==1) { 
       CCDirector.sharedDirector().popScene();
   } 
}

And of course this will work only if you pushed the About scene with :

  CCDirector.sharedDirector().pushScene(AboutScene.scene());

OTHER TIPS

you can do in this way on clicking back button

CCDirector.sharedDirector().getRunningScene().removeAllChildren(true);

Now create new scene

    sceneIndex--;
    CCScene scene = CCScene.node();
    scene.addChild(backAction());
    CCDirector.sharedDirector().replaceScene(scene);

Here backAction() is same as in cocos examples

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top