http://www.yiibai.com/lua/ 挺全面的一个lua教程
lua中游戏场景的基本搭建,包括类的继承、场景的创建、场景的进入、退出
—继承Layer类
local GameScene = class("GameScene",function()local layer = cc.Layer:create()
return layer
end)
--创建游戏场景
function GameScene.create()
local scene = cc.Scene:create()
local layer = GameScene.new() --调用 ctor() 构造函数
layer:init()
scene:addChild(layer)
return scene
end
-- 构造函数 退出 场景进入
function GameScene :ctor()
--场景节点事件处理
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()
end
function GameScene:onEnterTransitionFinish()
end
function GameScene:onExit()
end
function GameScene:onExitTransitionStart()
end
functionGameScene:init()
end
return GameScene
原文链接:https://www.f2er.com/cocos2dx/339932.html