资源描述:
《quick-cocos2d-x 学习系列之十五 状态机》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、quick-cocos2d-x学习系列之十五状态机1.代码--createFiniteStateMachineself.fsm_={}cc.GameObject.extend(self.fsm_):addComponent("components.behavior.StateMachine"):exportMethods()self.fsm_:setupState({events={{name="start",from="none",to="green"},{name="warn",from="green",to="yellow"},{name="p
2、anic",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("[FSM]STARTINGUP")end,onstart=function(event)s
3、elf:log("[FSM]READY")end,onbeforewarn=function(event)self:log("[FSM]STARTEVENT:warn!",true)end,onbeforepanic=function(event)self:log("[FSM]STARTEVENT:panic!",true)end,onbeforecalm=function(event)self:log("[FSM]STARTEVENT:calm!",true)end,onbeforeclear=function(event)self:log("[F
4、SM]STARTEVENT:clear!",true)end,onwarn=function(event)self:log("[FSM]FINISHEVENT:warn!")end,onpanic=function(event)self:log("[FSM]FINISHEVENT:panic!")end,oncalm=function(event)self:log("[FSM]FINISHEVENT:calm!")end,onclear=function(event)self:log("[FSM]FINISHEVENT:forthequalityof
5、reviewsandreview.Article26threview(a)theCCRAcompliance,whethercopiesofchecks;(B)whetherdoubleinvestigation;(C)submissionofprogramcompliance,investigationorexaminationofwhetherviewsareclear;(D)theborrower,guarantorloansclear!")end,onleavegreen=function(event)self:log("[FSM]LEAVE
6、STATE:green")end,onleaveyellow=function(event)self:log("[FSM]LEAVESTATE:yellow")end,onleavered=function(event)self:log("[FSM]LEAVESTATE:red")self:pending(event,3)self:performWithDelay(function()self:pending(event,2)self:performWithDelay(function()self:pending(event,1)self:perfo
7、rmWithDelay(function()self.pendingLabel_:setString("")event.transition()end,1)end,1)end,1)return"async"end,ongreen=function(event)self:log("[FSM]ENTERSTATE:green")end,onyellow=function(event)self:log("[FSM]ENTERSTATE:yellow")end,onred=function(event)self:log("[FSM]ENTERSTATE:re
8、d")end,onchangestate=function(event)self:log("[FSM]CHA