Sprite Sheets

Started by
2 comments, last by Krak 20 years, 9 months ago
I don't get how you could use one image of a bunch of different sprites with a black background, and use that one image of all the sprites to incorporate each sprite into a game individually. How does that work? [edited by - Krak on August 5, 2003 2:44:34 PM]
Advertisement
Use the texture coordinates. For example, if you want to use a sprite that takes up the lower left quarter of the texture, set the texture coordinates to (0, 0) for the bottom left corner of the sprite and (0.5, 0.5) for the top right. If you had a grid of 4x4 sprites in the texture, the texture coords for the first row/column would go from 0 to 0.25, the second from 0.25 to 0.5 and so on.
quote:Original post by Anonymous Poster
Use the texture coordinates. For example, if you want to use a sprite that takes up the lower left quarter of the texture, set the texture coordinates to (0, 0) for the bottom left corner of the sprite and (0.5, 0.5) for the top right. If you had a grid of 4x4 sprites in the texture, the texture coords for the first row/column would go from 0 to 0.25, the second from 0.25 to 0.5 and so on.


So if I had a 5*5 sheet of sprites, would the second sprite in the top row be located at (0.1, 0.5) or something like that?

I''m not sure if I 100% understand this.

The second sprite in the top row would be (0.2,0.8). In OpenGL texture coordinates go from bottom-left, to top-right, not top-left to bottom-right.

With a 5x5 sheet, each sprite takes 1/5 (or .2) of the texture. With an 8x8 sheet, each sprite takes 1/8 (or .125) of the texture. Etc. This assumes that the texture is completely filled with no unused space at the end (like with a 128x128 pixel image with only 4 16x16 sprites on it).

This topic is closed to new replies.

Advertisement