Reputation: 1578
I'm building a game for iOS using Cocos2D. In my game I have a pause menu that can be pulled up when playing the game. A simple tap will return from the pause menu to the game. What I would like to implement is a clean way to resume the game on the pause menu if the method applicationDidBecomeActive
is called. The problem is that only the appDelegate receives the call to applicationDidBecomeActive
, and my pause menu is many layers deeper than that. Right now I'm essentially passing the applicationDidBecomeActive
call through about 4 different layers to get it down to the pause menu. There must be a cleaner way?
Upvotes: 1
Views: 339
Reputation: 346
take a BOOL variable in appdelegate.h with property and synthesised it then when pause button pressed from any scene set this variable to yes. in applicationDidBecomeActive method of appdelegate check if(self.pause == YES) then don't resume ccdirector else resume it i used this in my game and it work fine when i press pause and then press home button and when come back the app is still pause. try this
Upvotes: 1
Reputation: 4291
Read about the NSNotificationCenter here and at Apple or just receive the UIApplicationDidBecomeActiveNotification anywhere.
Upvotes: 1
Reputation: 71008
Sure is. Just add an observer for the UIApplicationDidBecomeActiveNotification
from anywhere that's convenient. Application state changes can be hooked that way as well as via the app's delegate.
Upvotes: 3