<< Chapter < Page | Chapter >> Page > |
When you draw two or more sprites using the SpriteBatch.Draw method, you can specify the z-order as the last ( layerDepth ) parameter to the Draw method. By default, a non-transparent sprite that is drawn with a layerDepth value of 0.0 will hide sprites drawn with greater layerDepth values. The greater the layerDepth value, the further back will be the sprite in the z-order, up to a maximum value of 1.0, which represents the extreme back of thez-order.
During the design phase of project development, you can cause the program to interpret one specific color as being transparent by setting the Color Key Color property to that color and setting the Color Key Enabled property to true as shown in Figure 1 . Although I have never tried to do it, you can also apparently accomplish this at runtime by settingproperties of the TextureProcessor class.
Figure 1 . Property settings for green transparency.
Figure 1 shows the property settings required to cause every pixel having a color of pure green (0,255,0) to be replaced with transparent black, regardlessof the actual alpha value of the green pixel.
If you use this capability, you must be careful not to store your image in a file that uses lossy compression, such as a JPEG file. If you do, the pure colorthat went into the file is not likely to be pure when you later extract the image from the file. Instead, you should store your image in a lossless filesuch as a BMP file or a PNG file.
Even if you don't plan to use this capability, you need to be aware of it. It seems that any time you add an existing image file to the content folder, the Color Key Enabled property will be true by default and the Color Key Color property value will be magenta (255,0,255). If you fail to disable the Color Key Enabled property, all of your pure magenta pixels will be replaced by transparent black pixels.
In this module, I will present and explain an animated sequence in which a UFO flies over an alien planet. You will view the action as if the camerais trained on the UFO while maintaining a constant position relative to the UFO.
As the program runs, the planet gets larger and larger creating the illusion that the UFO is getting closer and closer to the surface of the planet. Finally,the program resets and the sequence repeats.
Notification Switch
Would you like to follow the 'Xna game studio' conversation and receive update notifications?