¿Cómo volver a la CCScene anterior?

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.

lo que necesito

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


preguntado el 25 de septiembre de 13 a las 09:09

2 Respuestas

Puede utilizar el CCDirector to push scenes on top of correr scenes. Say you have scene1 y scene2 both instances of CCScene (o una subclase de 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() { 
   if(backPressFlag==1) { 

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


Respondido el 25 de Septiembre de 13 a las 12:09

Thanks for the reply and I got your point but the point is, I have an android phone and on the back button of android. I need to handle this thing. If I cant figure out this then probably I'll choose this solution. - Akarsh M

oh you removed the iphone tag :). Can't you do it in the method handling the back button ?. Regardless of the input you should be able to use this. Just use a context telling you in what page you are in your application and use the above when you are in the about page - giorashc

I create a flag on every Scene and when the back button called. I applied the condition for handle the flag. condition always gives me right value but can't call the CCScene. It just throw me out the Application - Akarsh M

@Override public void onBackPressed() { super.onBackPressed(); if(backPressFlag==1){ CCScene scene = MainScene.scene(); CCDirector.sharedDirector().runWithScene(scene); } } - Akarsh M

So if you replace this code with the push/pop code it should work. I edited my answer. check it out - giorashc

you can do in this way on clicking back button


Now create new scene

    CCScene scene = CCScene.node();

Here backAction() is same as in cocos examples

Respondido el 25 de Septiembre de 13 a las 13:09

it's like.. I have a CCscene in which a single icon is present .. when I tap on it, take to the another CCscene And now I pressed back button which is the part of phone that time I want to show first ccscene... but in my case : activity closed - Akarsh M

I have update the code, now you can give me some suggestion for complete this thing - Akarsh M

create enum class and assign a varible each to the scene.When you press back then compare that enum variable and respond according to the scene. Ex: if(scene.mainSceme == enum.mainscene){ do ur task} - Rama

in the onBackPressed method , I'll check this or somewhere else - Akarsh M

in onBackPressed method only - Rama

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.