Game Development Reference
In-Depth Information
If you right-click a Flash Movie that is playing in a browser (with the menu option turned on in the
HTML embed), you will see an option called Show Re-draw Regions. Click this option, and you can
see screen invalidation in action. In a game that makes use of many display objects, you will see
red outlined screen invalidation areas all over the screen. In games that make use of full screen
blit techniques (you will see one in Chapter 11), you will see only a single red outline (or very few
depending on the number of blit canvases used).
Flash uses the vector render engine for all sprites unless they are specifically cached as a
bitmap. If a Sprite is set to Cache as Bitmap, and its display changes (or animates in some way), it
will need to be cached again each frame, causing the processor to do double duty. With a lot of
objects moving and animating on the screen, the Flash vector render engine will have to
invalidate almost every portion of the screen and redraw (and in cases of vectors cached as
bitmaps, cache) repeatedly. Since the Flash vector render engine is not the most efficient method
of displaying a bitmapped screen in this manner, we will explore different methods of using tiles
sheets and blitting to optimize the process.
We won't ignore the Flash vector render engine entirely though. You will see a good advantage to
using Flash sprites with a tile sheet in No Tanks!—rotation and scaling! Our game will not have
hundreds of on-screen objects. It will only contain relatively few moving or animating sprites. For
our game sprites (such as the tanks, missiles, and explosions), we will use a system we call
blitting to individual display objects . This means we will be combining the advantages of a tile
sheet with the advantages of the built-in Flash Sprite objects.
When we created our tile sheet for the tanks, we put in eight frames for each tank. Each frame
displays the tank treads slightly offset to simulate animation. We did not create versions of these
sprites on the tile sheet for the down, left, or right directions. We did this because when we blit
from a tile sheet to a Flash Sprite , we have the advantage of using the vector renderer's rotation
property to flip the Sprite to the desired direction.
In Chapter 11, we will create a game that blits to a single canvas (a full-screen blit). With a game
like that, we will not be able to make use of the Sprite class and the built-in vector render engine for
rotation. We will create our own system for rotation of blit objects to utilize rotation in that chapter.
Understanding the difference between tile and sprite sheets
You will hear both the terms “tile sheet” and “sprite sheet” used interchangeably. They are
essentially the same thing: an image file logically and physically split into regions that can be used
to display objects on the screen and animate them. Some tile-based games use a sheet full of
background tiles for rendering. They might have a separate sheet for sprite frames. We have mixed
background tiles on the same sheet as sprite frames for the No Tanks! game. It doesn't matter to
me that they are mixed together. In fact, it actually saves memory to combine them into one.
There are various ways that we can use tile sheets for blitting in Flash games. We will use two of
these techniques in this chapter:
A full screen blit
The full-screen blit is the most drastic version of blitting technique. It arguably provides the
greatest render speed benefits but at a cost. It is the most complicated and limiting blitting
procedure. It requires the developer to have one BitmapData object that we call a Canvas . All
objects are placed on to this canvas with copyPixels operations. There are no Sprite s,
MovieClip s, Bitmap s, or other objects added to the Flash display list other than a single Bitmap
Search WWH ::




Custom Search