Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 9. 2D Basics > Sprite Batches

Sprite Batches

First we need to understand the term sprite. A sprite is an image. XNA represents sprites with a Texture2D object. We load them just like we load textures for our 3D applications, as they are both images and get processed the same way. The difference is that in 3D we texture an object with the image, whereas in 2D we draw the image (or part of the image) on the screen. We saw an example of drawing part of an image in the last chapter. We applied different parts of an image to our skybox. The concept is the same, but the process is a little different. Really, we just pass in whole numbers instead of floats. Sprites are represented by x and y and as such have int values. It is impossible to draw something at pixel location 0.3, 0.3. If these types of values are passed in, XNA will do some anti-aliasing to make it appear that it is partially in the pixel area but the actual image location is rounded to a whole number.

We discussed the 3D coordinate system earlier and now we discuss the 2D coordinate system. The top left of the screen is the origin of the screen (0,0). The x axis runs horizontally at the top of the screen and the y axis runs vertically down the left side of the screen. It is identical to how a texture’s coordinate system is used. The difference is that instead of running from 0.0 to 1.0 like in a texture, the values run from 0 to the width and height of the screen. So if the resolution is 1024 x 768, the x values would run from 0,0 to 1024,0. The y values would run from 0,0 to 0,768. x runs from left to right and y runs from top to bottom. The bottom right pixel of the screen would be 1024,768. This can be seen in Figure 9.1.


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free 10-Day Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint