Game Development Reference
In-Depth Information
[bullet setDamage: 10];
LinearMotion* motion = [LinearMotion linearMotionInDirection:aDirection AtSpeed:3];
[motion setWrap:YES];
[bullet addBehavior: motion];
ExpireAfterTime* expires = [ExpireAfterTime expireAfter:240];
[bullet addBehavior:expires];
return bullet;
}
initAt:WithRadius:AndRepresentation:
, and we are adding the
behavior
objects
LinearMotion
and
ExpiresAfterTime
. These two
behavior
objects are used by the class
and are fully described in Chapter 6. The only new feature in the
Bullet
class is the class
, which was also used by the class
HealthBar
to indicate that this type of
VectorRepresentation
The Core Graphics library is interesting because it is not a vector graphics library (like SVG), but
it is excellent at rasterizing vector data structures. This makes a lot of sense if you consider that
Core Graphics was originally based on PDF. Core Graphics is a great library for rendering high-
quality graphics in a resolution-independent way. What this means for us is that our code will not
be specifying which pixel is which color, but instead will be describing shapes and how they should
be filled. Core Graphics is also known as Quartz. A complete description of the available drawing
functions can be found here:
http://goo.gl/6i5gr
.
In iOS, a
UIView
can specify how it is drawn by overriding the task
drawRect:
, getting a reference
to its graphics context and then calling a number drawing methods. Because our game engine
uses
UIView
's to represent each actor, we know that ultimately we will be creating a subclass
of
UIView
and calling the drawing code for our vector-based actors. It is the job the class
VectorRepresentation
to manage the relationship between the actor and the view that draws it
on the screen.
The VectorRepresentation Class
The
VectorRepresentation
class is responsible for creating a
UIView
suitable to draw our actor on.
Let's start exploring this class with the header for
VectorRepresentation
. See Listing 7-7.