码迷,mamicode.com
首页 > 其他好文 > 详细

Lua中添加触摸事件

时间:2015-07-29 22:51:23      阅读:224      评论:0      收藏:0      [点我收藏+]

标签:

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

Lua中添加触摸事件

标签:

原文地址:http://www.cnblogs.com/xiaohuihui1215/p/4687513.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!