You are browsing as a guest. Sign up (or log in) to start making projects!

11h 40m 22s logged

Fully functional animation parser and engine!

The entire thing started by me searching for assets to use for my game, then I found these super cute chibi characters that too FOR FREE!!

I downloaded one of the free ones and saw that they use .scml file for animations. They do have pre-rendered png images in sequence too, but that is too easy, not fun and doesn’t look good!

So, I planned to make a .scml parser, my own animation engine. And see how it goes.

In the added video there’s the working part and the non-working part, which I found pretty funny.

1. Image loader

First I made a image loader that dynamically loads all the sprites that are in use. Later I will add the abitily to drop the sprites from memory when not in use.

2. Mapping the data

This was, tough. Very, very tough that I had originally anticipated. Making this parser included me staring at a file with 9k lines for hours. Trying to figure out what each elements do and how to use them interconnectedly. I first made a scml_data.odin where I one by one mapped all the required data to odin structs.

3. .scml parser

I created a new file scml_parser.odin and in it I loaded the .scml file with Odin’s built in xml parser. The parsing took a big chunk of time too, as there are not good docs or examples available out here. But there was one single forum post that got me going and I never had any problems thereafter. I parse the file and save the values in my global private data variable defined in scml_data.odin.

I read each elements and added all the necessary ones. I observed all the attributes, data and values very carefully earlier so I had an idea of some repetitive values that I could skip. I think almost 50% of the file was repetition, which ofc I didn’t save.

4. The engine

Now that I had all the data with me in, the only thing I had to do was use that.

With a given time t I have to find the timeline that it lands on and interpolate the time, linearly lerp the values and issue a draw command for the single sprite.

I was unable to do two specific things and had to take help from AI:

  1. Lerping Angle: angle lerping is different as there can be a case where we have to learp from 350 to 10, normal lerp functions would just lerp it 350->200->10 instead of 350->360->10
  2. Using the parent bones to calculate the final position of the child node. The particular function ai generated is here.

Debugging

After making the engine, we got to fix the engine.

It had bugs, I debugged for a long time and then fixed them. Pretty stupid things like not pushing the timeline keys after initialising them, flipped y-axis, and angle clockwise order.

Final thoughts

Finally the thing is working now, I still have to polish it and make it play nicely with my entire game. There are other optimisation opportunities available but I’ll put that for later.

I will now work on the avatar menu, so user can mix different things.

0
9

Comments 0

No comments yet. Be the first!