Question

I am making a game in cocos2d. Game Scene has a menu button to take back to main menu which is a UIViewController. When user chooses to play again and same game scene is called to run in director, a pink screen appears on top of game scene.

It could be because of replacing the same scene with itself. So, I replaced it with an empty scene first when main menu is called. Code replacing scene is:

if ([[CCDirector sharedDirector] runningScene] == NULL) {
    [[CCDirector sharedDirector] runWithScene: [MySceneLayer scene]];
}
else {
    [[CCDirector sharedDirector] replaceScene:[MySceneLayer scene]];
}

It checks, if there is no scene running then starts the game scene first time. If some scene is already running, which in this case is an empty scene, then replaces it with game scene. The dealloc of game scene is also called which means that old scene is destroyed properly. Even then, replacing empty scene with game scene gives pink screen while replacing with any other new scene does not give any problem.

What can be the reason and what is the solution?

Was it helpful?

Solution

Finally, the problem caught and resolved. All it needs is careful play of adding and removing views. I was removing OpenGLView from superview when coming back to menu in UIViewController. While replacing the scene again, same

[[CCDirector sharedDirector] openGLView] 

which was in use earlier, had to be added back to the application window. Right place and right timing did it.

Any minor error in views or sprites can show you with pink screen :)

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