Stategraphs are mainly used for controlling animation and timing.

We can look at “SGeyeplant”, the stategraph for the Eye Plants that spawn with the Lure Plant, as an example. Its first state is “spawn” which gets played right when the Eye Plant is created. Notice that its “onenter” function plays some animations and plays a sound. It also listens for an “animover” event which gets triggered when the current animation finishes playing, which moves it to the “idle” state. All the idle state does is play the idle animation. Normally that kind of behaviour, “do this thing and when it’s done do that thing” is kind of a drudgery to code up, but the stategraph makes it straightforward to handle. We just tell it to go to the “spawn” state and when it’s done it will automatically end up idling.

Another interesting example is the “attack” state in SGtentacle. The¬†tentacles play sounds and deal damage during the “whipping” part of their animation, which occur at certain frames. So this state sets up a timeline which will do certain things at frames 2, 7, 15, etc. Again, we can set this all up in the stategraph, and then the combat component just says “go to your attack state!” and the timing gets taken care of over here.

"Stategraphs" doesn't have any sub pages.