cocos2dx lua 文件模板

前端之家收集整理的这篇文章主要介绍了cocos2dx lua 文件模板前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
--Template.lua

local Template = class("Template",function()
    return cc.Layer:create()
end)

--表的调用索引指向Template 
Template.__index = Template

-----------------------------自定义函数开始-----------------------------------------
function Template:load()
    local vSize=cc.Director:getInstance():getVisibleSize()
    --屏蔽层
    local tmpLayout=ccui.Layout:create()
    self:addChild(tmpLayout,0)
    tmpLayout:setContentSize(cc.size(2000,2000))
    tmpLayout:setTouchEnabled(true)
    --黑蒙层
    local grayLayer=cc.LayerColor:create(cc.c4b(0,125),2000,2000)
    grayLayer:setAnchorPoint(cc.p(0,0))
    self:addChild(grayLayer)
    grayLayer:setPosition(-100,-100)
 
    --点击领取按钮
    local function quitEvent(sender,eventType)
        if eventType==TOUCH_EVENT_BEGAN then
            btnPlaySound()
        elseif eventType==TOUCH_EVENT_ENDED then
        end
    end
    self.btn_quit:addTouchEventListener(quitEvent)
end
-----------------------------自定义函数结束-----------------------------------------

--自定义事件
function Template:onEnter()
    self:load()
end

function Template:onExit()
    -- cc.UserDefault:getInstance():setIntegerForKey("musicV",self.musicValue)
 --    cc.UserDefault:getInstance():setIntegerForKey("effectV",self.effectValue) 
end

function Template:cleanUp()
    _G.Template = false
end

function Template:init()
    local function onNodeEvent(event)
        if event == "cleanup" then
            self:cleanUp()
        elseif event == "exit" then
            self:onExit()
        elseif event == "enter" then
            self:onEnter()
        end
    end
    self:registerScriptHandler(onNodeEvent)
end


function Template:create()
    local o = Template.new()
        o:init()
    return o
end

function Template:createScene()
    local sceneGame = cc.Scene:create()
        sceneGame:addChild(self:create())
    return sceneGame
end

return Template
原文链接:https://www.f2er.com/cocos2dx/343366.html

猜你在找的Cocos2d-x相关文章