Optimization Question - Loading animation frames as several small separate pictures or as a giant spritesheet?

Hello all!

I'm putting some standing pictures in my game which will be animated constantly. For example, a picture of my character will constantly be in the corner of the screen doing a breathing loop, she'll play a little recoil if she gets hit by an attack, maybe some laughing animations when something funny happens, etc.

The point is my game will have quite a few animations running in the background at all times. Pretty big ones too. My game is going to be full HD (1920x1080). So we're talking like 500x500 size image frames. So they're not tiny little pixel animations and I'd like to optimize it as much as possible.

I have 2 options before me (as an example, I'll consider each picture frame to be 500x500 and an animation to be 50 frames long):

1. Make 20 different .png files each 500x500 and use the show picture command alongside the wait command to position them where I want them and play at the framerate that I want. (i.e. RPGMaker will need to load 50 small separate pictures).

2. Make a gigantic spritesheet (in this case around 3500x3500) and use Yanfly's picture spritesheet plugin commands to play the same animation, but instead referencing segments of the giant spreadsheet, once again making use of interspaced wait commands to control the framerate. (i.e. RPGMaker will load one very large picture and Yanfly's plugin will repeatedly reference different areas of the spritesheet).

Both options would accomplish the same thing - playing an animation on the screen. Which one would take less system resources on the average device? Would the answer change if it were, say, 5000 small pictures vs. a 35000x35000 spritesheet? Would it be the same with loops? (i.e. if I'm using an animation loop, would RPGMaker have to repeatedly load the same pictures over and over and would that be significant enough to be worse than the Yanfly plugin equivalent?)

Thank you for your time!
your main problem is the RAM/load circle, and that means that your answer will be different depending on how much RAM any given computer has.

A file needs to be loaded into RAM to be used. That will cause a delay on first use, and that delay will be larger the bigger the file is. But since the total data is the same, it means that you'll either have a large load delay for a large picture, or multiple small load delays scattered over time when the smaller pictures are needed.

Then it comes to the RAM-size. As long as all the pictures for the animation are in RAM, everything will run fluently - BUT the amount of RAM to store those pictures is used up and blocked for other use.
So what happens next will depend on how much RAM the player has, which might be less than what you have on your computer.

there is a function usually called "garbage collector" that checks when some RAM was last used and clears it to allow new data to be stored there. The exact process depends on how much RAM you have.
Alarge picture in constant use will be ignored by it - but it might cause RAM shortages that slow down the rest of the game, that part that has nothing to do with the animation.

a sequence of pictures might cause the garbage collector to delete the oldest data of the animation circle, requiring the engine to load the pictures again and again. This will cause flickering in the animation but not lag the rest of the game.

to prevent either you would have to make the size of the animation smaller, so that it requires less RAM to store, or to tell your players that they can only play with more than X GB RAM.


I can't tell you where your idea will end up on these mechanisms, but the descriptions should be enough for you to test it yourself...
A couple of things occur to me:

Based on my limited understand of how MV/MZ operate there's an image cache. I am not sure how dynamic the sizing is. If you google it, there's lots of conversations about checking it and clearing it, etcetera. Point is, filling it up might or might not be worth it. If the images you need are always cached, then no load times. But they could potentially interfere with other stuff loading. Or more to the point, prevent other imporant stuff from caching causing load times elsewhere.. Though on modern machines this should really not be an issue.

Another thing to consider: if your images can take it (without looking horrible, I mean), make slightly smaller images and scale them up in engine. They'll take less memory and load faster that way. showPicture will definitely do it, and I'd assume the YEP picture animation would as well.

And of course, the only real way to be sure: you're gonna have to test it. First on your dev machine, then find some crappy laptop that barely meets specs and test it there, then if you care about mobile, test it there.
your main problem is the RAM/load circle, and that means that your answer will be different depending on how much RAM any given computer has.

A file needs to be loaded into RAM to be used. That will cause a delay on first use, and that delay will be larger the bigger the file is. But since the total data is the same, it means that you'll either have a large load delay for a large picture, or multiple small load delays scattered over time when the smaller pictures are needed.

Then it comes to the RAM-size. As long as all the pictures for the animation are in RAM, everything will run fluently - BUT the amount of RAM to store those pictures is used up and blocked for other use.
So what happens next will depend on how much RAM the player has, which might be less than what you have on your computer.

there is a function usually called "garbage collector" that checks when some RAM was last used and clears it to allow new data to be stored there. The exact process depends on how much RAM you have.
Alarge picture in constant use will be ignored by it - but it might cause RAM shortages that slow down the rest of the game, that part that has nothing to do with the animation.

a sequence of pictures might cause the garbage collector to delete the oldest data of the animation circle, requiring the engine to load the pictures again and again. This will cause flickering in the animation but not lag the rest of the game.

to prevent either you would have to make the size of the animation smaller, so that it requires less RAM to store, or to tell your players that they can only play with more than X GB RAM.


I can't tell you where your idea will end up on these mechanisms, but the descriptions should be enough for you to test it yourself...

You reference a large delay for one big picture or smaller delays for the smaller pictures. But once the big picture is loaded, is that it? It's done and ready to go for the rest of that map now? Basically, if I had like a loading screen or something at the start of every map, could I mitigate the issue of the initial load delay on the large picture at the start of the map? Or are there continuous issues with large pictures that extend beyond the initial loading of the picture?


A couple of things occur to me:

Based on my limited understand of how MV/MZ operate there's an image cache. I am not sure how dynamic the sizing is. If you google it, there's lots of conversations about checking it and clearing it, etcetera. Point is, filling it up might or might not be worth it. If the images you need are always cached, then no load times. But they could potentially interfere with other stuff loading. Or more to the point, prevent other imporant stuff from caching causing load times elsewhere.. Though on modern machines this should really not be an issue.

Another thing to consider: if your images can take it (without looking horrible, I mean), make slightly smaller images and scale them up in engine. They'll take less memory and load faster that way. showPicture will definitely do it, and I'd assume the YEP picture animation would as well.

And of course, the only real way to be sure: you're gonna have to test it. First on your dev machine, then find some crappy laptop that barely meets specs and test it there, then if you care about mobile, test it there.

Yeah I guess you're right and I'll need to test it myself. It's just sort of a pain to set up all the animations in 2 different formats. :/
You reference a large delay for one big picture or smaller delays for the smaller pictures. But once the big picture is loaded, is that it?
yes and no - that is what the second part of my explanation was about.

IF the player has enough RAM to handle the big picture and the rest of the resources, then that would be it - but it would be the same for multiple smaller pictures if the RAM is large enough.

If the player has not enough RAM for that, then a number of smaller pictures would be better because they are easier to replace in RAM than one big picture.

Both ways have advantages and disadvantages, and the key to those is how much RAM a computer has. And that is something you can never know, unless you demand a high RAM as the game preference.
IF the computer has a high RAM, then the single large picture might be better - if not the multiple smaller pictures are usually the only way to go.
yes and no - that is what the second part of my explanation was about.

IF the player has enough RAM to handle the big picture and the rest of the resources, then that would be it - but it would be the same for multiple smaller pictures if the RAM is large enough.

If the player has not enough RAM for that, then a number of smaller pictures would be better because they are easier to replace in RAM than one big picture.

Both ways have advantages and disadvantages, and the key to those is how much RAM a computer has. And that is something you can never know, unless you demand a high RAM as the game preference.
IF the computer has a high RAM, then the single large picture might be better - if not the multiple smaller pictures are usually the only way to go.

I see now. I just reread your explanation and I think I understand. Thank you once again!

Original thread: https://forums.rpgmakerweb.com/threads/optimization-question-loading-animation-frames-as-several-small-separate-pictures-or-as-a-giant-spritesheet.132114/