Lua中添加触摸事件

1首先,lua中的触摸事件与cocos2d中的触摸事件相似,都需要添加监听者,都需要将监听者添加到触摸事件分发器中去

local listener=cc.EventListenerTouchOneByOne:create()

listener:registerScriptHandler(onTouchBegan,cc.Handler.EVENT_TOUCH_BEGAN )

listener:registerScriptHandler(onTouchEnded,cc.Handler.EVENT_TOUCH_ENDED)

local dispacther=cc.Director:getInstance():getEventDispatcher()

eventdispacther:addEventListenerWithSceneGraphPriority(listener, self)  

2触摸事件

function OnTouchBegan(touch,event)

        return true

end

function OnTouchEnded(touch,event)

      local p=touch:getLocation()

      print(p.x)

      print(p.y)

end

posted @ 2015-07-29 21:34  习惯了依赖你  阅读(5370)  评论(0编辑  收藏  举报