-1

While the user is playing the game if they tap the Home Button on iPhone/iPad the game pauses itself but doesn't stay paused if the user clicks back on the app to open it, instead game leads them to game over screen. How do I code it that once the user clicks Home Button the game pauses and if they click back on app, within 2 seconds the game unpauses and you continue. Is there a particular code that goes inside the following methods that pauses the entire game and then unpauses it after a someone clicks on it and a few seconds go by?

  UIApplicationDelegatedelegate 
  -(void)applicationWillResignActive:(UIApplication *)application{}
  -(void)applicationWillEnterForeground:(UIApplication *)application{}

I got the app to pause in the background and stay paused but how do I make it that when the user EnterForeground again, there's about a 2 second delay before the game un-pauses?

Merc
  • 313
  • 1
  • 4
  • 10
  • Roughly speaking your engine is not aware that it is paused, and thinks time has gone on while suspended. That's my guess anyway. – Almo May 27 '15 at 21:08
  • 2
    @Merc Don't forget to accept answers to your previous questions before posting more. http://stackoverflow.com/help/someone-answers – rmaddy May 27 '15 at 21:54
  • If this is what you meant by your previous question http://stackoverflow.com/questions/30487732/stop-game-app-if-home-button-clicked-ios then edit that question. Do not abandon the question and ask another that is almost the same. – matt May 27 '15 at 22:17

1 Answers1

1

iOS can't magically pause or un-pause your game for you - it's something you have to handle on your own in the code.

Once you have the logic to un-pause the game you can get the 2 seconds delay you mentioned in your question by calling performSelector:withObject:afterDelay: (see the docs). For example:

[self performSelector:@selector(continueGame) withObject:nil afterDelay:2.0]

where self has a method called continueGame to .. continue the game. :)

Peter Tutervai
  • 793
  • 12
  • 21
  • I actually currently use the above code as my code for there being a delay before the GameOver screen appears but I completely forgot. Thanks for reminding me and that works. – Merc May 27 '15 at 22:20