1

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?

Clev3r
  • 1,568
  • 1
  • 15
  • 28

3 Answers3

3

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.

(Docs here.)

Ben Zotto
  • 70,108
  • 23
  • 141
  • 204
1

Read about the NSNotificationCenter here and at Apple or just receive the UIApplicationDidBecomeActiveNotification anywhere.

Community
  • 1
  • 1
Norbert
  • 4,239
  • 7
  • 37
  • 59
1

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

Naimish Karia
  • 346
  • 1
  • 6