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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM