原文转自:http://blog.csdn.net/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) -- 参数 监听器 对象