Skip to content

Commit

Permalink
added pause/resume on backgrounding of iPhone host
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickmeehan committed Jul 11, 2011
1 parent 7209a32 commit 3d3dad5
Show file tree
Hide file tree
Showing 5 changed files with 12,227 additions and 12,189 deletions.
22 changes: 22 additions & 0 deletions xcode/ios/Classes/AppDelegate.mm
Expand Up @@ -75,6 +75,28 @@ -( void ) application:( UIApplication* )application didRegisterForRemoteNotifica
AKUAppDidRegisterForRemoteNotificationsWithDeviceToken ( deviceToken );
}

//----------------------------------------------------------------//
-( void ) applicationDidBecomeActive:( UIApplication* )application {

// restart moai view
[ mMoaiView pause:NO ];
}

//----------------------------------------------------------------//
-( void ) applicationDidEnterBackground:( UIApplication* )application {
}

//----------------------------------------------------------------//
-( void ) applicationWillEnterForeground:( UIApplication* )application {
}

//----------------------------------------------------------------//
-( void ) applicationWillResignActive:( UIApplication* )application {

// pause moai view
[ mMoaiView pause:YES ];
}

//----------------------------------------------------------------//
-( void ) applicationWillTerminate :( UIApplication* )application {

Expand Down
1 change: 1 addition & 0 deletions xcode/ios/Classes/MoaiView.h
Expand Up @@ -28,6 +28,7 @@
}

//----------------------------------------------------------------//
-( void ) pause :( BOOL )paused;
-( void ) run :( NSString* )filename;

@end
23 changes: 19 additions & 4 deletions xcode/ios/Classes/MoaiView.mm
Expand Up @@ -263,6 +263,19 @@ -( void ) onUpdateLocation :( LocationObserver* )observer {
);
}

//----------------------------------------------------------------//
-( void ) pause :( BOOL )paused {

if ( paused ) {
AKUPause ( YES );
[ self stopAnimation ];
}
else {
[ self startAnimation ];
AKUPause ( NO );
}
}

//----------------------------------------------------------------//
-( void ) run :( NSString* )filename {

Expand All @@ -273,10 +286,12 @@ -( void ) run :( NSString* )filename {
//----------------------------------------------------------------//
-( void ) startAnimation {

CADisplayLink* aDisplayLink = [[ UIScreen mainScreen ] displayLinkWithTarget:self selector:@selector( onUpdateAnim )];
[ aDisplayLink setFrameInterval:mAnimInterval ];
[ aDisplayLink addToRunLoop:[ NSRunLoop currentRunLoop ] forMode:NSDefaultRunLoopMode ];
mDisplayLink = aDisplayLink;
if ( !mDisplayLink ) {
CADisplayLink* aDisplayLink = [[ UIScreen mainScreen ] displayLinkWithTarget:self selector:@selector( onUpdateAnim )];
[ aDisplayLink setFrameInterval:mAnimInterval ];
[ aDisplayLink addToRunLoop:[ NSRunLoop currentRunLoop ] forMode:NSDefaultRunLoopMode ];
mDisplayLink = aDisplayLink;
}
}

//----------------------------------------------------------------//
Expand Down

0 comments on commit 3d3dad5

Please sign in to comment.