N
NilsRungholm
Guest
Hi. I'm prototyping a platformer, wherein I'm trying out different strategies for implementing a (finite) state machine in GML (not something I've done a lot of before). I'm wondering: what is a solid way to approach transitional animations (such as a confined animation transitioning from "stand" to "run")?
I initially tried to make each transition its own state. This had a few benefits, but also meant that my states had to be put into groups representing larger states, for most of the logic. Pseudo-example:
switch(myState)
{
case STATE.stand:
{
//All logic tied to "STATE.stand"...
} break;
case STATE.run:
case STATE.run_to_stand:
case STATE.stand_to_run:
{
//All logic tied to running (including transitioning to/from)...
} break;
}
Then, if I wanted to apply logic only when the state was equal to STATE.run_to_stand, I'd have to subsequently run another switch-statement. This quickly got convoluted, and sorta defeated the purpose of having an FSM.
My alternative approach was to only deal in the general states such as STATE.stand and STATE.run (as you'd normally do), and then perform the logic tied to the transitions inside the larger states (mainly checking to see whether an animation has finished) - this included a bunch of if-statements, and didn't feel elegant at all. So if I want tighter control over "transitional states" and behavior whilst running them.... what approach can I use?
Thanks in advance.
I initially tried to make each transition its own state. This had a few benefits, but also meant that my states had to be put into groups representing larger states, for most of the logic. Pseudo-example:
switch(myState)
{
case STATE.stand:
{
//All logic tied to "STATE.stand"...
} break;
case STATE.run:
case STATE.run_to_stand:
case STATE.stand_to_run:
{
//All logic tied to running (including transitioning to/from)...
} break;
}
Then, if I wanted to apply logic only when the state was equal to STATE.run_to_stand, I'd have to subsequently run another switch-statement. This quickly got convoluted, and sorta defeated the purpose of having an FSM.
My alternative approach was to only deal in the general states such as STATE.stand and STATE.run (as you'd normally do), and then perform the logic tied to the transitions inside the larger states (mainly checking to see whether an animation has finished) - this included a bunch of if-statements, and didn't feel elegant at all. So if I want tighter control over "transitional states" and behavior whilst running them.... what approach can I use?
Thanks in advance.