Game Development Reference
In-Depth Information
to create and update an actor's
UIView
. The protocol
Behavior
describes a task to be implemented
by any class that wishes to create a shared, reusable behavior. These classes and protocols are
covered in detail in the following sections.
The
GameController
Class
The
GameController
class coordinates the actors in the game and is ultimately responsible for
rendering each actor on the screen. This includes setting up
GameController
as a
UIViewController
,
defining a way to call our
updateScene
task repeated with a
CADisplayLink
, and finally reviewing
how
updateScene
manages the actors in the scene.
GameController
also provides a mechanism for
adding and removing actors. Let's take a look at the header for the class
GameController
, shown in
GameController.h
IBOutlet UIView* actorsView;
CADisplayLink* displayLink;
NSMutableSet* actors;
NSMutableDictionary* actorClassToActorSet;
NSMutableSet* actorsToBeAdded;
NSMutableSet* actorsToBeRemoved;
BOOL workComplete;
}
@property (nonatomic) long stepNumber;
@property (nonatomic) CGSize gameAreaSize;
@property (nonatomic) BOOL isSetup;
@property (nonatomic, strong) NSMutableArray* sortedActorClasses;
-(BOOL)doSetup;
-(void)displayLinkCalled;
-(void)updateScene;
-(void)removeActor:(Actor*)actor;
-(void)addActor:(Actor*)actor;
-(void)updateViewForActor:(Actor*)actor;
-(void)doAddActors;
-(void)doRemoveActors;
-(NSMutableSet*)actorsOfType:(Class)class;
@end