单点触摸:按下,移动,松开
function FightScene:onTouchBegan(touch,event)
print("触摸开始")
return true
end
function FightScene:onTouchMoved(touch,event)
print("触摸移动")
return true
end
function FightScene:onTouchEnded(event)
print("触摸结束")
return true
end
function FightScene:onEnter()
--获得当前节点Node的监听器
self.touchListener = cc.EventListenerTouchOneByOne:create()
--监听器上注册触摸事件
self.touchListener:registerScriptHandler(handler(self,self.onTouchBegan),cc.Handler.EVENT_TOUCH_BEGAN )
self.touchListener:registerScriptHandler(handler(self,self.onTouchMoved),cc.Handler.EVENT_TOUCH_MOVED )
self.touchListener:registerScriptHandler(handler(self,self.onTouchEnded),cc.Handler.EVENT_TOUCH_ENDED )
--eventDispatcher是Node的属性,通过它管理当前节点(场景、层、精灵等)的所有事件的分发,但它本身是一个单例模式值的引用,通过self:getEventDispatcher()方法获得。
local eventDispatch = self:getEventDispatcher()
--绑定Node方式添加EventListener
eventDispatch:addEventListenerWithSceneGraPHPriority(self.touchListener,self)
end
@H_502_79@