Game Development Reference
In-Depth Information
Chapter 7
Build Your Game: Vector Actors
and Particles
Core Graphics is a powerful 2D drawing library that is responsible for rendering large portions of
iOS and OS X. In this chapter, we see how to use this library to draw actors in our game. The goal
is to have actors that are drawn dynamically based on game state. To illustrate this, we'll create two
example actors drawn with Core Graphics: a health bar that shows the amount of health remaining
for an actor, and a bullet that is drawn in a particular color depending on how powerful it is. These
two examples will illustrate how to use Core Graphics within the context of the simple game engine
we have started.
We will accomplish this by creating a new class called VectorRepresentation , which is analogous to
the class ImageRepresentation from the previous chapter. The class VectorRepresentation will be
used to create a UIView to represent our actor, and be drawn with custom code using Core Graphics.
We'll also look at another popular technique used in games to create a compelling visual: the
particle system. Stated simply, a particle system is anything in a game that generates lots of little
graphics that, when composed on the screen, create an overall effect more interesting than the
sum of its parts. Particle systems are used in games to create fire effects, water effects, and spell
effects, to name a few.
In this chapter, we use particle systems to create comets that are composed of a large number
of simple particle actors to give the comets a glowing, fluid feel. We are also going to use this
technique to illustrate a little realism when an asteroid breaks apart.
The sample code for this chapter can be found in the Xcode project Sample 06+07.
Saucers, Bullets, Shields, and Health Bars
In this example, we will look at four new actors: saucers, bullets, shields, and health bars. The code
for this section is found under the group Example 2, in the Xcode project Sample 06+07.
159
 
Search WWH ::




Custom Search