Game Development Reference
In-Depth Information
a child to actorsView . For each step of the animation, GameController changes the location, scale,
and transparency for each Actor's UIView . The key tasks for GameController are as follows:
doSetup . In the task doSetup , a subclass of GameController should
specify the subclasses of Actor that should be kept sorted by calling
setSortedActorClasses: . Also, any audio files to be played should be prepared
by calling prepareAudio: .
applyGameLogic . The task applyGameLogic is called once for every step of the
animation. It is in this task that subclasses should implement all game logic,
including:
Setting end-of-game conditions
Adding and removing Actors
Keeping score
Tracking achievements
Updating heads-up display (HUD)
actorsOfType: . The task actorsOfType : is used inside of the applyGameLogic
to find all Actors of a particular class. The type of actor requested needs to be
specified during doSetup with the setSortedActorClasses : task.
addActor :/ removeActor :. The tasks addActor : and removeActor : are how actors
get added and removed from the game. These tasks collect all Actors added or
removed during an animation step, and then apply those changes all at once at
the end of the animation loop. This prevents modification of the collections that
hold the actors, so any subclass of Actor or GameController can add or remove
any Actor during their apply task.
Managing user input (touches, gestures, and so on)
Actor
The Actor class represents anything that is dynamic in a game. In our example, the ship, asteroids,
saucers, power-ups, health bars, particles, and bullets are all actors. When creating a game, a
subclass of GameController will handle the big details about the game, but it is the subclasses of
Actor that provide the unique and interesting behaviors of each item in the game. In practice, each
Actor in the game is a composition of its properties, how it is drawn (Representation), how it behaves
(Behaviors), and the custom code defined in a subclass. We will look at Representations and
Behaviors after we look at the class Actor. The following is a list of the properties of an Actor and
what each means.
long actorId : The actorId is a unique number assigned to each Actor. This
value can be used to provide a soft reference to Actors in the game.
BOOL added / removed : The properties added and removed can be used to test if an
Actor has successfully been added or removed from a game.
 
Search WWH ::




Custom Search