lua 中处理cocos2dx 的button 事件

时间:2024-01-12 15:48:56

lua 中处理cocos2dx 的button 事件

2014-05-08 09:44:32|  分类: lua |举报 |字号 订阅

1、引入这个类:require "GuiConstants"

2、下面是回调函数的处理.

local function menuZhuCeCallback(sender,eventType)
        print(sender:getTag())
        if eventType == ccui.TouchEventType.began then
            print("按下按钮")
        elseif eventType == ccui.TouchEventType.moved then
            print("按下按钮移动")
        elseif eventType == ccui.TouchEventType.ended then
            print("放开按钮")
        elseif eventType == ccui.TouchEventType.canceled then
            print("取消点击")
        end
end

3 、对button事件的调用处理。获得button对象

local button_close=mianye:getChildByTag(4);
            button_close:addTouchEventListener(menuZhuCeCallback)