Is it better to use spritesheets instead of individual images?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By epark009

My Google search on this topic hasn’t given me a straight answer so I’ll just ask it here.

Suppose I have many sprites of varying size, such as background elements for a stage. The images are unrelated to each other in terms of animation, but will almost always show up together. How badly will it impact performance if I kept each of these sprites in separate files instead of a spritesheet? Does it matter?

Someone on Reddit claimed Godot Engine can be set to automatically generate spritesheets on export but I haven’t seen an option for that.

Just to comment, i found this website that combine all sprites into one sprideSheat:
Images to Sprite Sheet Generator

marcelo | 2020-10-12 01:02

:bust_in_silhouette: Reply From: ser_patrick

Using a spritesheet is more manageable as development proceeds. Individual sprites would require naming each and every file of a single sprite(NPCs and PCs alike but specially if you have many NPCs/enemies which will get more and more time consuming.).

As for the performance issue I think it might not be a healthy practice in case where ‘sprite animation’ is concerned .I’m still combing through the docs(and came here looking for an answer for my own problem) but having some background in pixel art animation believe me when I say managing individual sprite images is a mess.

Although some spritesheets might require you to specifically work with individual images in case you decided to give your players some shapeshifting powers. But that can also be managed by multiplying the size of the canvas in accordance with the final transformation but what if you want the newly transformed sprite interacting with the environment in some different way I mean what if him being a human deals him more damage by some environmental trap than being an abominable monster.

The naming of every sprite isn’t really an issue for me, since I’m already naming every sprite in the drawing software I’m using. I can easily export every sprite I created and automatically named. The names don’t show up in my game though because I’m trying to use spritesheets, but I was wondering if spritesheets even matter. For example, I have a tree, a bush, and a cloud, all different shapes and not going to animate into each other, but will almost always show up together. Should these be placed in a single spritesheet? Putting these in a spritesheet is a hassle for me, the developer, but I currently do it because I believe it’ll help performance. I wanted to know if it significantly impacts performance or if I’m wasting my time. File reads are often one of the slowest operations in a program, but maybe Godot does something clever with sprites?

epark009 | 2019-06-21 17:12

Well of course placing different elements of a scene into only one spritesheet is not advisable and I don’t think using independent sprite images would result in performance slack off. After all game engine’s have been built from ground up with optimization of different game elements in mind. And if you are familiar with importing spritesheet animations remember how those softwares ask us to allocate the the type and width(aseprite). Even though if you have many sprites in a single spritesheet the engine will break it down into individual and then save them(and you can confirm this by taking a peek inside the project folder of your game).

So now it boils down to this if you are wasting time making Spritesheets (which from your second comment is clear) stop it but man if you are comfortable with this then carry one no one’s gonna stop you.

ser_patrick | 2019-06-21 20:31

So I should not use spritesheets then. That will make my workflow much easier.

I’m unsure where the broken down images are located. Is it the StreamTexture file in the .import folder? I only see 1 file for my spritesheet in here if it is.

epark009 | 2019-06-21 20:48

:bust_in_silhouette: Reply From: Dooowy.

Use spritesheets for big projects. By big projects I mean anything you really want to optimize. Sprite sheets are great at critical load times but the lading of them is barely seeable (below 8ms for 250x250 sprite). Benefit of sprite sheet Is that It loads data once only so the loading spike is only at the beginning while an individual sprite animation would require loading dynamically, spikes at each frame. A workaround i found was to have a persistent object handle loading sprite via c#.
If your not making high res textures use individual sprite and preload them.

:bust_in_silhouette: Reply From: epark009

Just as an additional note to anyone else who happens upon this thread, there’s a ResourcePreloader node where you can add textures to preload. This should solve the file loading issue if it ever becomes one. Of course if you have too many files in the preloader, then it would take a long time to load and will probably also hog a lot of memory, so don’t go overboard.