首页 > 其他 > 详细

Lua中添加触摸事件

时间:2015-07-29 22:48:41      阅读:854      评论: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

(1)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!