Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

callinfix

macrumors newbie
Original poster
Jan 24, 2011
1
0
I want the methods pauseGame in customized UIView - MyGameView get invoked when the phone is locked or interrupted. So I have a pauseGame method but it can't stop the timer when user lock screen (command+L).

The lock screen did appear but the game still running at the background. So I added the testPause method to MyGameView and MyGameAppDelegate (parallel to pauseGame in order to test if the code inside pauseGame in fact causing any problem). So I put a breakpoint to it to debug MyGameAppDelegate.

When ran in debug mode, I activated the screen locked and the code did stop at the breakpoint. But when I tried to step into the testPause method, it didn't take me to the testPause method in MyGameView (it just passed it, not skipped) and no message was printed on terminal by NSLog. Why? What did I miss?

Code:
//
// MyGameAppDelegate.h
// MyGame
// #import <UIKit/UIKit.h>
@class MyGameViewController;
@class MyGameView;

@interface MyGameAppDelegate : NSObject {
UIWindow *window;
MyGameViewController *viewController;
MyGameView *view;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet MyGameViewController *viewController;
@property (nonatomic, retain) IBOutlet MyGameView *view;
@end

Code:
//
// MyGameAppDelegate.m
// MyGame
//

#import "MyGameAppDelegate.h"
#import "MyGameViewController.h"
#import "MyGameView.h"

@implementation MyGameAppDelegate

@synthesize window;
@synthesize viewController;
@synthesize view;
- (void)applicationWillResignActive:(UIApplication *)application {
/*
Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. */
[view pauseGame];
[view testPause];
}
@end
Code:
//
// MyGameView.h
// MyGame

@interface MyGameView : UIView {
- (void)pauseGame;
- (void)testPause;
@end

Code:
//
// MyGameView.m
// MyGame
// #import "MyGameView.h"
#import "AtlasSprite.h"
#import "MyGameViewController.h"
#import "SecondViewController.h"

@implementation MyGameView
- (void)pauseGame {
[theTimer invalidate];
theTimer = nil;
}
- (void)testPause{
NSLog(@"TestPause");
}
@end
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.