SOLVED How should i change my sprites when i have many of them on my player?

I'm trying to achieve a cleaner and reduced code to animate my character, basically it has 16 directions and it's respectives animations on each one of them (Idle, Running, Attack...).
For now i'm making it work with 16 " if " statements for each direction but also, i'm repeating these 16 if statements for each one of my character States, so i have 16 direction checks for idle, 16 direction checks for running, 16 direction checks for attack and so on.

What i want to do but i don't really know how i should, is to check the position, then check in wich State my character is and then select the sprite related to it in that direction.

If this helps i already have my direction statements stored into variables (pos1, pos2, pos3...).
I thougth on something using maybe multi dimensional arrays, but i don't really know if this would be possible or the best way.
Just for an example something like this:

characterDirAndState [CurrentPosition, CurrentState] = DesiredSprite;

I don't know if i managed to explain it in a clear way, but i'll reply if someone needs a better explanation 🙏.


Forum Staff
An array sounds like a good start, especially since I'm seeing the typical pattern of numbered variables (pos1, pos2, pos3...) that really should be an array. You may want to add a dimension for the state there, and before you know it, you have a fully automatic state + direction -> sprite mapping.
I'm just kinda lost on how i would execute it, i can store in the two dimensional array like:

Array [Pos1] [IdleState] = Current_Sprite;

But how would i read them dynamically as my character changes it's directions and states?
Last edited: