quick Cocos2d-x 3.2rc0的状态机运行下面代码会报错:attempt to call method ‘setupState’(a nil value),新手上路,望大神帮解,万分感谢
self.fsm_ = {}
cc.GameObject.extend(self.fsm_)
:addComponent("components.behavior.StateMachine")
self.fsm_:setupState({
events = {
{name = "idle", from = "*", to = "idle" },
{name = "move", from = "idle", to = "move"},
{name = "attack", from = {"idle", "move", "hit"}, to = "attack" },
{name = "hit", from = "idle", to = "hit" },
{name = "dead", from = "hit", to = "dead"},
},
callbacks = {
onbeforestart = function(event) self:log(" STARTING UP") end,
onstart = function(event) self:log(" READY") end,
onbeforewarn = function(event) self:log(" START EVENT: warn!", true) end,
onbeforepanic = function(event) self:log(" START EVENT: panic!", true) end,
onbeforecalm = function(event) self:log(" START EVENT: calm!", true) end,
onbeforeclear = function(event) self:log(" START EVENT: clear!", true) end,
onwarn = function(event) self:log(" FINISH EVENT: warn!") end,
onpanic = function(event) self:log(" FINISH EVENT: panic!") end,
oncalm = function(event) self:log(" FINISH EVENT: calm!") end,
onclear = function(event) self:log(" FINISH EVENT: clear!") end,
onleavegreen = function(event) self:log(" LEAVE STATE: green") end,
onleaveyellow = function(event) self:log(" LEAVE STATE: yellow") end,
onleavered = function(event)
self:log(" LEAVE STATE: red")
self:pending(event, 3)
self:performWithDelay(function()
self:pending(event, 2)
self:performWithDelay(function()
self:pending(event, 1)
self:performWithDelay(function()
self.pendingLabel_:setString("")
event.transition()
end, 1)
end, 1)
end, 1)
return "async"
end,
ongreen = function(event) self:log(" ENTER STATE: green") end,
onyellow = function(event) self:log(" ENTER STATE: yellow") end,
onred = function(event) self:log(" ENTER STATE: red") end,
onchangestate = function(event) self:log(" CHANGED STATE: " .. event.from .. " to " .. event.to) end,
},
})