Game Development Reference
In-Depth Information
Figure 6-3. Random point offscreen
In this image, you can see the gray rectangle, which is the same size as the variable gameSize . The
dot in the middle is the CGpoint gameCenter . The black line going from gameCenter to the upper-
left corner of gameSize is of the length distanceFromCenter . The value of distanceFromCenter is
calculated based on the X and Y components of gameCenter , using the Pythagorean theorem. Using
gameCenter and distanceFromCenter , we can get a random point on the outer circle by calling
randomPointAround:At : from the class Actor (shown earlier in Listing 6-10).
In Listing 6-13, after calculating the center point and picking a radius of 32, we have to create a
Representation object to handle the drawing of this power-up. Because we want to use a series of
images to represent power-ups, we create an instance of ImageRepresentation called rep and set
the properties backwards and stepsPerFrame . ImageRrepresentation is passed to Actor 's initAt:W
ithRadius:AndRepresentation : task to set rep as the power-up's representation. Also note that we
set the Powerup as the rep's delegate. This means that the instance of Powerup we are creating will be
used to specify information about how to draw this actor.
Inspecting ImageRepresentation
Because we want to separate the game logic regarding an actor and how it is drawn, we are
introducing the class ImageRepresentation . This class is responsible for creating the objects
necessary for rendering an actor with a UIView. Primarily, ImageRepresentation will be created
UIImageViews with the PNG files in order to draw our actors. Let's take a look at the header of
ImageRepresentation , shown in Listing 6-14.
 
Search WWH ::




Custom Search