# How should I go about handling nonuniformed sprite sheet with JSON data?

This might be a lenghty question so bare with me.

I'm developing a 2D game i Monogame framework and I'm stuck with it comes to handle large sprite sheets with different frame width, height and animation. I want to load a sprite sheet that has different animation.

Like this one

Taken from this question

Some frames in this sprite sheet have different width and height, meaning that I can't use a uniform split with spritesheets width / amount of columns because it will not work with all the frames. I have used a tool that gives me cordinates in JSON format like this

{
"@imagePath": "sprites.png",
"SubTexture": [
{
"@name": "spriteframe1.png",
"@x": "862",
"@y": "0",
"@width": "112",
"@height": "120"
},
{
"@name": "spriteframe10.png",
"@x": "0",
"@y": "320",
"@width": "252",
"@height": "156"
}
}


But here I have problem understanding how I should handle these different frames. How can I switch between animation frames and make sure that the animation loops with state of the object?

E.G If the object in this case flies, I want to loop trough the wing animation but how should I handle it so that only the "Fly-frames" are being looped?

At the moment I have all the frames in a list where every element is a frame with its own x,y,width and height metadata.

• It looks like your data format provides a string name for every frame. Could you not use that to select the flying frames in order? – DMGregory Mar 4 at 12:33
• Yeah I have thought about that but I can't really grasp on how. – Bojje Mar 4 at 12:34
• Well, what did you try? Presumably you started by editing your JSON data to give the sprites meaningful names, then you wrote some code that walks through the array looking for particular names, right? Show us that, and where it's giving the wrong results or not getting you where you need to be. – DMGregory Mar 4 at 12:36
• No I have not started with looping trough my list. But I'm doing this atm. Using the name probably is the best way I guess. – Bojje Mar 4 at 12:41