Game Development Reference
In-Depth Information
Updating the ASM to call callbacks
Handling callbacks within the ASM must occur in three different places. A helper
HandleCallbacks function is useful in order to reduce duplicating code.
The first case we need to handle is when the ASM transitions to a state that contains call-
backs. This particular case has two different variations: one where a transition exists within
the ASM and another when no transition exists.
The last case we handle is when animations loop. When updating the current state of the
ASM, an additional check is required in order to see whether stepping the ASM will cause
the animation to loop. A while loop is used to handle callbacks in this case, as it's pos-
sible for an animation to loop multiple times within a single step of the ASM.
Note
While an animation can loop multiple times within a single ASM time step, this typically
doesn't happen, and any example callbacks we write won't consider this case.
AnimationStateMachine.lua :
local function HandleCallbacks(self, stateName)
if (self.stateCallbacks_[stateName]) then
CallCallbacks(
self.stateCallbacks_[stateName], stateName);
end
end
function AnimationStateMachine.Update(
self, deltaTimeInMillis, currentTimeInMillis)
...
if ((currentAnimTime + deltaTimeInSeconds) >=
currentAnimLength) then
ClearAnimation(self.currentState_.animation_);
Search WWH ::




Custom Search