Question

I have a UISplitviewController app that's structured like the picture in this question:

UISplitViewController on iPad with Storyboards?

When I click on either Game #1 or Game #2, their respective game run. However, if I click on the second game (either #1 or #2), I get this error:

Terminating app due to uncaught exception
'NSInternalInconsistencyException', reason: 'You can't run an scene
if another Scene is running. Use replaceScene or pushScene instead'

How can I check to see if there's already an existing Cocos2d scene and replace it when the second game is clicked? Ideally, I think I should keep both games running so the user can click back to the other game. Is this possible?

I tried to simply replace this line: [director runWithScene:scene];

with this line: [director replaceScene:scene];

Unfortunately, I get an error CCTextureAtlas.m, in method:

-(void) drawNumberOfQuads: (NSUInteger) n fromIndex: (NSUInteger) start {...}

enter image description here

[Update]

I think I might need to stop the scene so everything is cleaned up properly. When I click on my Help screen, for example, my controller's viewWillDisappear gets called. This does not happen when switching between Cocos2d view controllers.


After following these instructions, and only creating the EAGLView once, I almost have it working, but I get a black screen for the second scene. Note that I do briefly see the new scene.

Was it helpful?

Solution

How can I check to see if there's already an existing Cocos2d scene and replace it when the second game is clicked?

if ([[CCDirector sharedDirector] runningScene] == nil) {
        [[CCDirector sharedDirector] runWithScene:sceneToRun];
    } else {
        [[CCDirector sharedDirector] replaceScene:sceneToRun];
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top