How to kill a cocos2d scene directly without repla

2019-09-04 04:45发布

问题:

I'm starting the game with a UIViewController in this way:

navController = [[MyNavigationController alloc] initWithRootViewController:myController];

and when you push the game button the game start the scene in this way:

[[CCDirector sharedDirector] runWithScene:gameScene];

ok, now when I want to quit I just replace the UIViewController (because I did the menu with UIKit and the game with cocos2d) with the starting view controller to do the animation I want, it works fine... but obviously the old running scene still remains in memory, it is not deallocated in any way, I need to remove the scene and make the app as it was at the first running.

The replaceScene didn't work, I just need to stop the running scene and make everything as it was when the app started running, from the [CCDirector sharedDirector] direcly, how can I do it? popScene won't work too.

回答1:

you can remove the CCDirector from the application.

the director is a simple UIViewController so, you can call

[[CCDirector sharedDirector] removeFromParentViewController];

and after call the [[CCDirector sharedDirector] end]; to remove the singlenton instance