Game Development Reference
In-Depth Information
Adding callbacks to the ASM
To add a callback to the ASM, we store the callback function as well as an arbitrary data
member to be passed back to the callback when invoked. This data member allows for any
specific information the callback might require, such as a reference to the agent or the sol-
dier mesh:
AnimationStateMachine.lua :
function AnimationStateMachine.AddStateCallback(
self, name, callback, data)
if (self:ContainsState(name)) then
if (not self.stateCallbacks_[name]) then
self.stateCallbacks_[name] = {};
end
table.insert(
self.stateCallbacks_[name],
{ callback = callback, data = data });
end
end
function AnimationStateMachine.new()
...
asm.stateCallbacks_ = {};
asm.AddStateCallback =
AnimationStateMachine.AddStateCallback;
...
end
Search WWH ::




Custom Search