Rendering Sprites

Direct3D already has an object that can be thought of as a sprite, namely the texture. However, textures must be rendered onto some type of primitives in order to be seen by the user. The Sprite class handles this work for you. Add the following variables for your application:

private Texture spriteTexture;
private Sprite sprite;
private Rectangle textureSize;

These obviously store the texture that will be used to render the sprite, as well as the sprite itself. You will also need to know the size of the texture in order to render it correctly, so that will be stored as well. At the end of your initialization method, directly after the device has been created, you will need to initialize these variables as follows:

 // Create ...

Get Managed DirectX® 9 Kick Start: Graphics and Game Programming now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.