1.Cocos Studio编辑器编辑出来的UI csb文件导入进来,生成lua文件
local result = require("导出文件名").create()
self:addChild(result.root)
2.从studio导入文件中获取相对应的控件名称
local button = ccui.Helper:seekWidgetByTag(self, 逻辑标签)
3.是否设置定时器由需求决定
self.scene:scheduleUpdate(handler(self, self.step))
function PlayerScene:step(dt)
end
4.触摸的回调函数
local listener = cc.EventListenerTouchOneByOne:create()
listener:registerScriptHandler(handler(self, self.onTouchBegan), cc.Handler.EVENT_TOUCH_BEGAN)
self.scene:getEventDispatcher():addEventListenerWithSceneGraphPriority(listener, self.scene)
function PlayerScene:onTouchBegan(touch, event)
return true
end
5.按键监听函数
local function onrelease(code,event)
if code == cc.KeyCode.KEY_BACK then
end
end
local listener = cc.EventListenerKeyboard:create()
listener:registerScriptHandler(onrelease,cc.Handler.EVENT_KEYBOARD_RELEASED)
self:getEventDispatcher():addEventListenerWithSceneGraphPriority(listener,self)
网友评论