The Skeleton Application
By now, we should have a well-rounded framework with all of the basic functionality to begin creating our game. In addition, we have a number of example states showing how to use each feature available. Before we move on to the next chapter, we should create a skeleton application that ties all of the states together to show off our work.
Since we already have the framework and example states, all we need to do is create a Main menu state that will allow us to navigate to each example. The fastest way to do this is with Interface Builder:
Select Xcode file→New File→User Interfaces→View XIB and name the file gsmainmenu.xib.
Select Xcode file→New File→Cocoa Touch Classes→NSObject subclass and name the new class
gsMainMenu.Modify gsMainMenu.h so that the class inherits from
GameStateinstead ofNSObject.Add
#include"GameState.h"to the top of gsMainMenu.h.Add an
IBOutletto gsMainMenu.h for the view that you will load from gsmainmenu.xib:IBOutlet UIView* subview;
In gsMainMenu.m, override
initWithFrame: andManager:to manually load gsmainmenu.xib and set up the subview:-(gsMainMenu*) initWithFrame:(CGRect)frame andManager:(GameStateManager*)pManager { if (self = [super initWithFrame:frame andManager:pManager]) { //load the gsmainmenu.xib file here. this will //instantiate the 'subview' uiview. [[NSBundle mainBundle] loadNibNamed:@"gsmainmenu" owner:self options:nil]; //add subview as... a subview. This will let everything //from the nib file show up on screen. ...
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