Is application:didFinishLaunchingWithOptions: really a good place to initialize cocos2d and its OpenGL ES view?

StackOverflow https://stackoverflow.com/questions/7889557

Question

Cocos2d templates and the usual sample projects initialize cocos openGL ES view and other stuff in the applicationDidFinishLaunching / application:didFinishLaunchingWithOptions: method. In relation to the last method, Apple iOS Programming Guide states that:

"Apps that use OpenGL ES should not use this method to prepare their drawing environment. Instead, they should defer any OpenGL ES drawing calls to the applicationDidBecomeActive: method."

So, my question is, is application:didFinishLaunchingWithOptions: really the proper place to initialize cocos2d? or should we be doing that in applicationDidBecomeActive: ?

If you think that applicationDidBecomeActive: is the way to go, what would be the consequences in relation to background execution? i.e. what should we do to avoid a sort of double initialization when the app comes to foreground from being inactive?

Thanks in advance

Was it helpful?

Solution

Good question … so far 99.9% of all cocos2d apps do it the way cocos2d does it and I haven't heard of a single issue.

Since Apple doesn't really explain why this is particularly important for OpenGL ES apps, I would assume the following:

  • OpenGL ES apps tend to take a relatively long time to initialize their view. In particular when loading lots of assets. This could lead to the App being killed by the system if it takes too long. That means the Cocos2D first scene should load fast, and in particular it shouldn't load all the game's assets unless loading of the first scene is deferred to applicationDidBecomeActive. The latter requires an additional check to make sure there's no other scene already running.
  • Apps are supposed to perform common tasks in applicationDidBecomeActive. This is generally good advice because some settings can now change while the app is suspended. For example the user might change the device language, or enter Airplane Mode and the app needs to respond to that when it becomes active again. Some changes may affect OpenGL ES apps in particular, like for example reloading all bitmap fonts if the user changed locale from english to japanese.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top