Game Development Reference
In-Depth Information
what object is representing the interface and where the actual
method is in memory. This is actually true of the regular desktop
Flash Player as well, but its impact is barely felt in that environ-
ment, if at all. However, on an iOS device, frequent memory look-
ups during the course of a performance-intensive application like a
game can result in degradation. In the case of the previous exam-
ples, because the methods in question are called pretty infrequently
over the course of the application, it would not have a noticeable
impact on performance. However, the other interface mentioned,
IGamePiece, has methods that are called quite often during the
game,soitmighteventuallybecome necessary to reference those
classes directly. Ultimately, like with so many elements of Flash, it
comes down to striking a balance between performance and practi-
cality. Sometimes the performance of your game has to come
before following every best practice to a tee.
A Real-World Example
ll now look at a very simple program example that could feasi-
bly be used in a game and see how it performs when utilizing bit-
map caching. In the spirit of the classic example I
ve referenced a
number of times in this chapter, it will consist of several
floating across a slowly tiling background. It will also
demonstrate the use of object recycling to keep the memory foot-
print as low as possible, as well as a utility to measure frame rate
performance without any tricky debugging.
The XFL Document
You can find the XFL file for this application in the Chapter 15
examples folder. If you open the document, you
ll find a library
with just five items in it: two images, two Sprite symbols, and a
component. The main timeline does not have any object placed on
it other than an instance of the FrameRate Profiler component (for
ease of setting the component parameters). We
ll return to this
component shortly
ll start with
the classes for the two Sprites as the document class references
them later and it will be helpful to know how it works.
for now let
s jump into the code. I
This class is extremely simple as it just contains the code needed to
update its position based on a constant value. This code could
arguably exist in the main document class instead, but this would
provide the flexibility to add more functionality later and keep the
main class from getting cluttered.
Search Nedrilad ::

Custom Search