The App Delegate
One of the classes Xcode created for us was AppDelegate. This is the first piece of code
that gets loaded when our program is run, and the last to unload. We are
going to modify this class to inherit from GameStateManager
because it is going to manage all of the important GameStates in our game. Like the other classes,
GameStateManager.m and GameStateManager.h are located in the Classes subdirectory. Begin by modifying the
Test_FrameworkAppDelegate class:
//Test_FrameworkAppDelegate.h #include "GameStateManager.h" @interface Test_FrameworkAppDelegate : GameStateManager <UIApplicationDelegate>
When our application starts up, the applicationDidFinishLaunching function is called
on our AppDelegate to let us start
initializing our game. We need to do two things here: start our main loop
code and create an instance of our first GameState.
Add the following code to your AppDelegate class (don’t forget to add the
appropriate header functions):
//Test_FrameworkAppDelegate.m #include "Test_FrameworkAppDelegate.h" - (void) applicationDidFinishLaunching:(UIApplication *)application { //set up main loop [NSTimer scheduledTimerWithTimeInterval:0.033 target:self selector:@selector(gameLoop:) userInfo:nil repeats:NO]; //create instance of the first GameState [self doStateChange:[gsMain class]]; } - (void) gameLoop: (id) sender { [((GameState*)viewController.view) Update]; [((GameState*)viewController.view) Render]; [NSTimer scheduledTimerWithTimeInterval:0.033 target:self selector:@selector(gameLoop:) ...Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access