标签:cocos2d-x c++ 开发人员 游戏 cococs2d-xlua
场景(Scene)以及所有节点(Node)的生命周期事件如下:require "Cocos2d" require "Cocos2dConstants" local SettingScene = require("SettingScene") local size = cc.Director:getInstance():getWinSize() local GameScene = class("GameScene",function() return cc.Scene:create() end) function GameScene.create() local scene = GameScene.new() scene:addChild(scene:createLayer()) return scene end function GameScene:ctor() ① cclog("GameScene init") --场景生命周期事件处理 local function onNodeEvent(event) if event == "enter" then ② self:onEnter() elseif event == "enterTransitionFinish" then ③ self:onEnterTransitionFinish() elseif event == "exit" then ④ self:onExit() elseif event == "exitTransitionStart" then ⑤ self:onExitTransitionStart() elseif event == "cleanup" then ⑥ self:cleanup() end end self:registerScriptHandler(onNodeEvent) ⑦ end function GameScene:onEnter() ⑧ cclog("GameScene onEnter") end function GameScene:onEnterTransitionFinish() ⑨ cclog("GameScene onEnterTransitionFinish") end function GameScene:onExit() ⑩ cclog("GameScene onExit") end function GameScene:onExitTransitionStart() ? cclog("GameScene onExitTransitionStart") end function GameScene:cleanup() ? cclog("GameScene cleanup") end … … return GameScene
local function onNodeEvent(event) if event == "enter" then ② self:onEnter() elseif event == "enterTransitionFinish" then ③ self:onEnterTransitionFinish() elseif event == "exit" then ④ self:onExit() elseif event == "exitTransitionStart" then ⑤ self:onExitTransitionStart() elseif event == "cleanup" then ⑥ self:cleanup() end
京东:http://item.jd.com/11659697.html
欢迎关注智捷iOS课堂微信公共平台,了解最新技术文章、图书、教程信息标签:cocos2d-x c++ 开发人员 游戏 cococs2d-xlua
原文地址:http://blog.csdn.net/tonny_guan/article/details/45674709