原文转自:http://blog.youkuaiyun.com/liyoushihaer/article/details/39501665
local function onTouchEnded(touch,event)
local poin = touch:getLocation()
print(" X:")
end
local function onTouchBegan(touch,event)
local tt =touch:getLocation()
print("x",tt.x,"y:",tt.y)
return true -- 必须返回true 后边的move end等才会被处理
end
local function onTouchMoved(touch,event)
local poin = touch:getLocation()
print(" y:")
end
local listener = cc.EventListenerTouchOneByOne:create() -- 单点触摸监听
-- cc.EventListenerTouchAllAtOnce:create() -- 多点触摸
listener:registerScriptHandler(onTouchBegan,cc.Handler.EVENT_TOUCH_BEGAN) 前一个参数是回调函数后一个参数是对应事件
listener:registerScriptHandler(onTouchMoved,cc.Handler.EVENT_TOUCH_MOVED )
listener:registerScriptHandler(onTouchEnded,cc.Handler.EVENT_TOUCH_ENDED)
local dispacher = layerBg:getEventDispatcher()
dispacher:addEventListenerWithSceneGraphPriority(listener,layerBg) -- 参数 监听器 对象
本文介绍了一个使用Cocos2d-x游戏引擎实现触摸事件处理的例子,包括触摸开始(onTouchBegan)、触摸移动(onTouchMoved)和触摸结束(onTouchEnded)的回调函数,并展示了如何注册这些事件处理函数。
274

被折叠的 条评论
为什么被折叠?



