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
