Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LIBGDX is it better to use spritesheet or individual images?

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?

like image 468
kubaork Avatar asked Jan 22 '14 09:01

kubaork


2 Answers

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.

like image 103
noone Avatar answered Nov 09 '22 05:11

noone


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.

like image 45
Robert P Avatar answered Nov 09 '22 03:11

Robert P