views:

2752

answers:

2

What is the best size for an individual tile in a 2D sprite sheet?

I am creating a sprite sheet and am trying to figure out what the best resolution is to use for each sprite. Is there a standard size I shouldn't go above or below?

ex. 64px X 64px, 512px X 512px, etc.

I am trying to get HD quality sprites. Think Alien Hominid, Castle Crashers, or World of Goo. Some examples would be nice too, so if you have sprite sheet example please upload them.

+3  A: 

This depends on how the sprite is going to be rendered, as well as what you are going to do with them when you render them.

If you are going to avoid scaling the sprites, making them the same as their final rendered resolution as possible will help keep the quality higher. I would definitely stick to power of two texture sizes, since it does seem to help in general.

However, if you're going to be doing a lot of transformations on your sprites, particularly with rotations or scaling, you may want to go slightly larger than the resolution they will render, since the resampling may be slightly better quality. You'll want to consider how many sprites are being composited and displayed at any time, and what hardware you'll be running on (xbox, pc, both?), to determine the best options for balancing performance with texture quality.

If you're not going too crazy with the number of sprites, though, you can probably go at a higher quality, and allow the system to downsize them as needed, and get good results.

Reed Copsey
So you are saying there isn't a standard when it comes to texture sizes?
Khalid Abuhakmeh
No - it depends on usage and need. Ideal sprite texture sizes depend on how (and how large) you will render them.
Reed Copsey
alright, I understand. So there isn't a "Right" size? I just have to play around and pick what is right for me.
Khalid Abuhakmeh
Yeah :) That's part of the fun. "Right" is a balance - higher resolution == more flexibility in quality, at the expense of resources, so it's always a balance which is unique per application.
Reed Copsey
+2  A: 

This may not directly answer your question, but I wanted to throw in what I've learned when using sprite sheets. Sprite sheets are great because the fewer textures that the GPU has to switch between when drawing to the screen, the better performance.

I would recommend that you take a look at the XNA sprite sheet example, if you haven't already. It offers a couple great benefits:

  • It automatically packs your sprites (in different files) into one big texture. I thought keeping my artwork in separate files and having the one giant sprite sheet generated automatically would be better than keeping all my art in one file.

    For example, what if I decide I want my animations to have an extra frame in the middle? Then I have to shift around a bunch of stuff in the sprite sheet to make room for the new frame. If I'm using one file per frame, it's just a one line change to the XML file listing what goes into the sprite sheet if I want to add a new frame in the middle.

    It can be a pain to list every frame file separately, so I can see why this may not work for some people, but it was great for my project. Also, I found that the gain of being able to swap textures in and out of my sprite sheet easily was more than worth it, which will help you as you determine what size of sprites to use.

  • We ran into a problem when scaling sprites. I believe that link describes the issue pretty well. In any case, this sprite sheet example will automatically add a 1 pixel border (using the color of the pixel that was originally on the edge) around each sprite you add to the sprite sheet, which will protect you from seeing oddly colored borders around your sprites when scaling, because it still only draws the sprite using the original size. It just uses the extra border for interpolation instead of a nearby sprite's pixels or white space.

Reed is correct that there really isn't any standard sprite size you should use. It depends mostly on what type of game you are doing, what type of scaling and rotating you are doing, etc. However, there are specific sizes you need to watch for when using sprite sheets. Sprite sheets are just one giant texture, but there is a limit to how big of a texture GPU's can hold in their memory. The XBOX360 supports up to 4096x4096 (I think) textures. If you're programming for Windows, then it depends on the user's graphics card. From what I've seen, it's probably best to stick with 2048x2048 on Windows, because most graphics cards can support at least that much.

One last note on the sprite sheet example. I don't believe that it will watch for a maximum sprite sheet size, so if you do use it, you may want to add a couple lines to catch when the size of the generate texture is larger than you want to support.

Venesectrix
Thanks, I have looked at that example and will probably go that route. 2048 x 2048 sounds really high, do you have an example of a sprite sheet that would be that large?
Khalid Abuhakmeh
Let's say you had some animations for different characters in a game. If each sprite was 64x64 and each character had 4 different animations with 10 frames each. That would already be 2560x64 (if you had them all in one row). If you had 32 different characters, you could fill the sheet.
Venesectrix
I just pulled those numbers out of the air. It really depends on how big your game is, how many different animations, objects, etc. and the size of those objects. Important thing is just to realize you don't want to go over those max sizes or switch textures too often when drawing with SpriteBatch
Venesectrix