quick StateMachine 状态机的使用

quick 的状态机 真是使用简单,功能强大,,记录一下使用方式便于以后使用 1:创建一个状态机StateMachine (1) self.fsm_ = StateMachine.new() (2)self:addComponent(“component.behavior.StateMachine”) self.fsm_ = self:getComponent(“component.behavior.StateMachine”) 2:setupState

self.fsm_:setupState({events= {{name = “start”, from = “none”, to = “green” },{name = “warn”, from = “green”, to = “yellow”},{name = “panic”, from = “green”, to = “red” },{name = “panic”, from = “yellow”, to = “red” },{name = “calm”, from = “red”, to = “yellow”},{name = “clear”, from = “red”, to = “green” },{name = “clear”, from = “yellow”, to = “green” },},callbacks = {onbeforestart = function(event) self:log() end,onstart = function(event) self:log() end,onwarn = function(event) end,…onchangestate = function(event) print(event.from,event.to) end}})

执行状态跳转

.fsm_:doEvent(“clear”)end

注意一开始一定要doEvent(“start”) 状态从none 转为 green状态

更详细的一些函数使用参照

影子依旧可以相亲相爱。哪一块骨骼最温暖,总能一击即中。

quick StateMachine 状态机的使用

相关文章:

你感兴趣的文章:

标签云: