加载csb文件,并且绑定其中的控件
local MainScene = class("MainScene", cc.load("mvc").ViewBase)
function MainScene:onCreate()
--加载cocostudio生成的loginscene.csb文件
local uiRoot = cc.CSLoader:createNode("loginscene.csb")
uiRoot:addTo(self)
self:initEvent(uiRoot)
end
function MainScene:initEvent(uiRoot)
--获取loginscene.csb文件中的按钮,以及时间绑定
local button = uiRoot:getChildByName("btn_login");
if button then
button:addTouchEventListener(function (event,type)
if type == ccui.TouchEventType.began then
print("点击按钮开始")
end
if type == ccui.TouchEventType.ended then
print("点击按钮结束")
end
end)
end
end
return MainScene