Game Development Reference
In-Depth Information
There are two lines I commented out in the source code for this
example, which can be found in the Rock class. They consist of
two trace commands: one is called when a new rock is created and
the other when a rock is
If you uncomment these lines
and export this SWF to run in the AIR player, you
recycled.
ll see that in
practice, the application creates a whole slew of rocks from scratch
at the beginning and then begins to transition to using existing
rocks instead. This change is not immediate since the speed of the
rocks is variable, and it will take a little while for enough rocks to
have been created to account for this latency.
'
The FrameRateProfiler Class
The final piece of this application, which we
ll examine, is not
directly related to SpaceRocks at all. Instead, it is a utility class that
will prove useful going forward for measuring the performance of
Flash applications on iOS. It is based on a class I created (dis-
cussed in the online bonus chapter on debugging and performance
issues, found at www.flashgamebook.com ), which displays the
actual frame redraw rate (as opposed to the intended rate) of a
SWF. The previous version used a text field to simply display the
frame rate as a number. When I initially dropped it into Space-
Rocks to use, I saw immediate performance degradation. This is
becauseIwasplacingalive-updatingtextfield(whichcannotbe
cached to the GPU) directly over objects that the GPU was trying
to render. The net result was that the CPU still had to composite
everything, so I lost all intended performance gain from using
cachAsBitmapMatrix to begin with.
This new version of the profiler takes a graphical approach. It
creates two simple vector boxes (one white, one green), caches
them to the GPU (so that they can sit on top of everything else and
be properly composited), and then adjusts the scaleX value of the
one on top to reflect the percentage of the intended frame rate.
Figure 15.1 shows how this looks in practice. As it is not pertinent
to the current example, I won
'
t step through all of the code
for the profiler here, but feel free to peruse it in the Chapter 15
examples folder. Now, let
'
'
s look at a full game example for iOS.
Part 2: Marble Runner
One of the reasons the new mobile devices such as the iOS and the
Android families are garnering such appeal from a broad range of
users is their simple yet sophisticated approach to user input. Most
devices (aside from those with a slide-out keyboard) have any-
where from one to four buttons. All other inputs are handled by
one of two ways: either by touch interaction with the screen or
through the use of the built-in accelerometer. This mechanism
Search Nedrilad ::




Custom Search