Higher Performance With Spritesheets Than With Rotating Using C# and XNA 4.0?
Posted
by
Manuel Maier
on Game Development
See other posts from Game Development
or by Manuel Maier
Published on 2012-06-18T15:55:10Z
Indexed on
2012/06/18
21:24 UTC
Read the original article
Hit count: 197
I would like to know what the performance difference is between
using multiple sprites in one file (sprite sheets) to draw a game-character being able to face in 4 directions and
using one sprite per file but rotating that character to my needs.
I am aware that the sprite sheet method restricts the character to only be able to look into predefined directions, whereas the rotation method would give the character the freedom of "looking everywhere".
Here's an example of what I am doing:
Single Sprite Method
Assuming I have a 64x64 texture that points north.
So I do the following if I wanted it to point east:
spriteBatch.Draw( _sampleTexture, new Rectangle(200, 100, 64, 64), null, Color.White, (float)(Math.PI / 2), Vector2.Zero, SpriteEffects.None, 0);
Multiple Sprite Method
Now I got a sprite sheet (128x128) where the top-left 64x64 section contains a sprite pointing north, top-right 64x64 section points east, and so forth.
And to make it point east, i do the following:
spriteBatch.Draw( _sampleSpritesheet, new Rectangle(400, 100, 64, 64), new Rectangle(64, 0, 64, 64), Color.White);
So which of these methods is using less CPU-time and what are the pro's and con's?
Is .NET/XNA optimizing this in any way (e.g. it notices that the same call was done last frame and then just uses an already rendered/rotated image thats still in memory)?
© Game Development or respective owner