6

I'm new in LIBGDX, I made 40 frames for "hero running" sprite and I don't know if it's better to use spritesheet or individual images. Spritesheet will be very large, because I want high resoultion even on 1080p devices. Can you tell me in which case (spritesheet or individual images) performance will me better?

kubaork
  • 161
  • 2
  • 12

3 Answers3

11

Since the other answers here are not pointing you in the wrong direction, but aren't 100% accurate, I'll add a more detailed explanation.

In case of an animation it should not make a difference performance-wise!

Whether you use a spritesheet or individual images, they will only be sent to the GPU once. The only difference with spritesheets is that you just bind the texture once and you won't be forced to change it anymore when rendering different things.

But this does not really apply to your hero animation. Whether you use a spritesheet or an individual image, in every frame you need to bind the texture again, and draw either just a part of it (in case of spritesheet) or the whole image (in case of individual images), because in between two frames, you also render other non-hero things.

An exception to this would be, if you draw several heroes in one frame. Using individual images, you would have to switch the texture every time, because the heroes are probably not synced. In case of a spritesheet, you bind the texture only once and then draw all heroes with that once sheet-texture (only a single texture-bind will happen in this case).

However you will for sure gain a performance increase, if you make your character-animation-spritesheet a part of another, "bigger" spritesheet, where also other textures are packed into. This way you can draw your character and other things again with just a single texture-binding.

The only problem with spritesheets is, that they tend to waste some space. Especially on mobile devices when you are forced to use POT (power of two) sized textures, this can make a difference.

noone
  • 19,520
  • 5
  • 61
  • 76
  • OpenGL (which LibGDX uses internally) is a state machine. Every state-change (and a texture-binding is such a change of state) is costly and degreases the performance :) – noone Jan 22 '14 at 14:01
  • +1 thanks for answer :-) Could you tell me how big can be sprite sheet? Can be bigger than 1024x1024? I target devices with >= 2.2 android – kubaork Jan 23 '14 at 10:25
  • 1
    @kubaork It differs. Please see http://stackoverflow.com/questions/16931295/android-devices-gl-max-texture-size-limitation-safe-texture-size and http://stackoverflow.com/questions/8573178/limitation-on-texture-size-android-open-gl-es-2-0 – noone Jan 23 '14 at 10:34
2

I think it is better to use TextureAtlases (should be some Kind of spritesheet). Notice that some older Android devices can't load images which are biger then 512*512. If you don't target old devices you should set your maximum to 1024*1024 px. So if your spritesheet takes more then that you should split it up in more then one.

Robert P
  • 9,398
  • 10
  • 58
  • 100
2

Spritesheets are much more efficient.

In OpenGL (which Libgdx is a wrapper around), a texture is drawn by being sent to the graphics card. The reason why SpriteSheets are used, is that the whole texture only needs to be "sent" once, and then separate segments of the image can be drawn per sprite frame. This is much faster than binding a new texture for each frame, which would be very wasteful in terms of resources.

jamiebuckley
  • 118
  • 7