Game Development Reference
In-Depth Information
Creating the
UIImageView
is as simple as creating a
UIImage
based on the
imageName
of the actor
and creating a new
UIImageView
with it. We then put the
UIImageView
into the
NSMutableDictionary
actorViews
, again using the actor's ID as the key. Lastly, we add the new
UIImageView
to
actorView
.
We set the frame of the new
UIImageView
to a size zero frame to prevent some redraw issues. The
frame will be updated shortly anyway.
Placing UIImageView in the Screen
After creating the
UIImageView
(if required), we have to figure out where on the screen it should be
drawn. The first step is to figure out the relationship between the size of the game area and the
actual size of
actorView
on the screen. We can simply divide the width of the
actorView
by the width
of the game area to establish our
xFactor
. We do the same operation with the heights to figure
yFactor
. Once we have these ratios, we can calculate the
frame
of the
UIImageView
. Once
frame
of the
UIImageView,
we set it. Figure
5-10
Figure 5-10.
Converting game coordinates into screen coordinates