cocos2dx 3.X Lua複選框的用法ccui.CheckBox

本文用的圖片資源是採用官方test中的,可自行在cocos2dx引擎中搜索文件名找到該資源哦.
需要把函數寫在前面,否則,後面調用的時候會說無法找到該函數,lua中提示函數爲nil....

--響應事件函數

local function selectedEvent(sender,eventType)

    if eventType == ccui.CheckBoxEventType.selected then

        cclog("eventType == ccui.CheckBoxEventType.selected  ")

    elseif eventType == ccui.CheckBoxEventType.unselected then

        cclog("ccui.CheckBoxEventType.unselected  unselected  ")

     end

 end   

--創建複選框         

local checkBox = ccui.CheckBox:create()

checkBox:setTouchEnabled(true)

checkBox:loadTextures("check_box_normal.png",

            "check_box_normal_press.png",

            "check_box_active.png",

            "check_box_normal_disable.png",

            "check_box_active_disable.png")

checkBox:setPosition(cc.p(120300))   --座標

checkBox:addEventListenerCheckBox(selectedEvent)  --註冊事件
layerFarm:addChild(checkBox,10)  --添加到圖層

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章