Created
August 24, 2010 22:24
-
-
Save thiagosf/548450 to your computer and use it in GitHub Desktop.
Multi-tarefa para iOS4, colocar no AppDelegate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is how i did it: | |
// To pause: | |
- (void) applicationDidEnterBackground:(UIApplication *)application | |
{ | |
[[CCDirector sharedDirector] stopAnimation]; | |
[[CCDirector sharedDirector] pause]; | |
} | |
- (void)applicationWillResignActive:(UIApplication *)application | |
{ | |
[[CCDirector sharedDirector] stopAnimation]; | |
[[CCDirector sharedDirector] pause]; | |
} | |
// When resuming: | |
- (void)applicationDidBecomeActive:(UIApplication *)application | |
{ | |
[[CCDirector sharedDirector] stopAnimation]; // call this to make sure you don't start a second display link! | |
[[CCDirector sharedDirector] resume]; | |
[[CCDirector sharedDirector] startAnimation]; | |
} | |
/* | |
Someone else suggested a BOOL flag to make sure you don't call animation methods twice, but I find calling stopAnimation before startAnimation does the trick just as well... | |
An important thing to note is that applicationDidBecomeActive: is called also when you program starts for the first time, so if you call startAnimation there, without first stopping it, or checking for "first run", then you will have two display links running and no amount of stopAnimation will save your program from crashing when it is backgrounded... | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment