Generate 2D animation on the spot or read from file?

Hello there community,

I’m currently making a 2D game engine for a RPG and everything I have so far works, except from going fullscreen for some reason, but I started to think about my animation system so far. So right now I use big spritesheets and generate frames for animations, based on a given textureregion, texture frame size and amount of frames from that big spritesheet when the game requires me to, these “frames” are rectangles that indicate what to draw from the spritesheet, nothing special.
But what if I generate ALL the possible animations at once and save them in for example multiple XML files, like BasicNPCAnimations.xml, MonsterAnimations.xml,… (I’ll be writing the frames rectangles and something like the name of the animation to the XMLs). Then if I’m required to load the animations I’ll let my game read the right XML file and find the right animation based on name or ID and get the properties of my frames that way.

My question would be which one of these would be the best and fastest way to get my game to load animations… Or if you know an even better method, tell me what you use and I’ll look into it…

Well I think that the method I have right now is safer and easier to modify for more custom animations, also it generates these frames just once and disposes of them once you’re out of the region where you could encounter them… To me using XMLs to store premade animation data and to load it later seems rather “ambiguous”. It might just be stupid to ask something like this but it just came to me and I just don’t know if it would be for the better to change my system.

Note: I’ve used +80 different animations, for testing purposes, on 1 screen, as in render all at the same time, to test my performance and I didn’t encounter any issues :smile: mostly 64 x64 and128 x128 in pixels

I wouldn’t worry about saving your animations to XML files unless you’re using an editor to do it for you. Generating the Rectangle frames is probably faster than loading from XML. However, I would consider pre-generating all possible animations when the level (or game) loads. Re-creating all these lists during gameplay will generate garbage and occasional framerate hitches (possibly only noticeable on non-desktop platforms).

Yes, thank you for your confirmation, I actually do load all my possible animations when the level itself loads… so yeah, thanks once again :slight_smile: