cocos2dx lua touch事件监听 鼠标事件监听

    local listener = cc.EventListenerTouchOneByOne:create()
    listener:setSwallowTouches(true)
    listener:registerScriptHandler(handler(self, self._onTouchBegin), cc.Handler.EVENT_TOUCH_BEGAN)
    listener:registerScriptHandler(handler(self, self._onTouchMove), cc.Handler.EVENT_TOUCH_MOVED)
    listener:registerScriptHandler(handler(self, self._onTouchEnd), cc.Handler.EVENT_TOUCH_ENDED)
    listener:registerScriptHandler(handler(self, self._onTouchCancelled), cc.Handler.EVENT_TOUCH_CANCELLED)
    self:getEventDispatcher():addEventListenerWithSceneGraphPriority(listener, self)

    local listener = cc.EventListenerMouse:create()
    listener:registerScriptHandler(handler(self, self.mouseMove), cc.Handler.EVENT_MOUSE_MOVE)
    listener:registerScriptHandler(handler(self, self.mouseScroll), cc.Handler.EVENT_MOUSE_SCROLL)
    self:getEventDispatcher():addEventListenerWithSceneGraphPriority(listener, self)

 

你可能感兴趣的:(【COCOS】)