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