• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GameMaker Transitional animations in a state machine

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.
 

Hyomoto

Member
Congratulations! You've discovered the limitations of a basic state machine! This is a good thing, every person who has ever tried to implement one has hit this roadblock and shouted, "There has to be a better way!" And the answer is: maybe. So first off, I recommend very highly that you read this chapter of the book Game Programming Patterns by Bob Nystrom. It's only twenty pages maybe, and I think you'll really enjoy it. As you read you'll go, "Yes, exactly!" And when done, filled with new confidence and excitement, you'll crack open GM2 and say ... how do I even implement any of that? At that moment, I'll be glad to help answer your question.

Then again, after reading you might also go "I UNDERSTAND THIS PERFECTLY." And need no further assistance, either way I promise that chapter will do more for you than a dozen posts here.
 
Top