Download Sample Chapters from Book.

Transcript
© 2009 NURVE NETWORKS LLC “Inside the XGS PIC 16-Bit”
Sprite Transparency
Sprite transparency allows you to use a single color code (0 in our case) to represent “transparent” or see thru.
Therefore, any pixel of the bitmap that represents the sprite that is drawn with the transparent color will allow you to
see the background. Figure 15.21 shows and example of transparency and opaque background.
Figure 15.21 – Transparent and non-transparent sprite rendering.
As you can see, the transparent sprite on the right is what you would expect. However, the transparency comes at a
price – there is a lot more calculation for the sprite engine since it has to test each pixel value for transparency and
then if transparent draw the background tile map data, else draw the sprite bitmap. Therefore, sprites without
transparency have their place as well. For example, if you are placing a sprite on a background with a constant
background color (like the sky in this example), you could use a non-transparent sprite, but simply set its background
color (black in this case) to the background color and that big rectangular region of opacity in the non-transparent
version wouldn’t be noticeable. Another good example is a “space game”. In games, where the background is
primarily black, you don’t need or care about transparency.
In any event, transparency costs computation, so the sprite engines have limitations with this feature that we will get
to shortly.
Scaling
One of the more powerful features that many sprite engines have (since they are hardware based in many cases) is
that the sprites can be scaled on the fly before rendering. In other words, you may define a sprite as only a 8x8 or
16x16 bitmap, but when its drawn you can set the “scale” of the sprite to 1x,2x,4x, etc. however the particular sprite
engine works. In our case, the sprites are always drawn as 1x and at this time they do not support scaling. In the
future this may change so make sure you read the header file information on the engines to find out their exact
features and limitations.
Working with Sprites
First, sprites are supported only in tile map engines. You could add sprites to a bitmap engine in your own design, but
historically sprites are added to tile map engines to overcome the constraints of the tile maps themselves. Also, it’s
very important that you realize that each sprite engine might have slight differences in the number of sprites and the
features that each sprite supports. The only way to figure this out is to open up the source code for the tile map driver
and read the information at the top of the file. Each driver clearly explains the number of sprites and what they
51