eventManager Class

Module: cc

cc.eventManager is a singleton object which manages event listener subscriptions and event dispatching.

The EventListener list is managed in such way so that event listeners can be added and removed
while events are being dispatched.

Index

Methods
  • pauseTarget Pauses all listeners which are associated the specified target.
  • resumeTarget Resumes all listeners which are associated the specified target.
  • hasEventListener Query whether the specified event listener id has been added.
  • addListener

    Adds a event listener for a specified event.
    if the parameter "nodeOrPriority" is a node, it means to add a event listener for a specified event with the priority of scene graph.
    if the parameter "nodeOrPriority" is a Number, it means to add a event listener for a specified event with the fixed priority.

  • removeListener Remove a listener.
  • removeListeners Removes all listeners with the same event listener type or removes all listeners of a node.
  • removeAllListeners Removes all listeners
  • setPriority Sets listener's priority with fixed value.
  • setEnabled Whether to enable dispatching events
  • isEnabled Checks whether dispatching events is enabled

Details

Methods

pauseTarget

Pauses all listeners which are associated the specified target.

meta description
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/event-manager/CCEventManager.js:140
Parameters
resumeTarget

Resumes all listeners which are associated the specified target.

meta description
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/event-manager/CCEventManager.js:164
Parameters
hasEventListener

Query whether the specified event listener id has been added.

meta description
Returns Boolean
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/event-manager/CCEventManager.js:716
Parameters
addListener

Adds a event listener for a specified event.
if the parameter "nodeOrPriority" is a node, it means to add a event listener for a specified event with the priority of scene graph.
if the parameter "nodeOrPriority" is a Number, it means to add a event listener for a specified event with the fixed priority.

meta description
Returns EventListener
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/event-manager/CCEventManager.js:727
Parameters
  • listener EventListener | Object The listener of a specified event or a object of some event parameters.
  • nodeOrPriority Node | Number The priority of the listener is based on the draw order of this node or fixedPriority The fixed priority of the listener.
removeListener

Remove a listener.

meta description
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/event-manager/CCEventManager.js:804
Parameters
  • listener EventListener an event listener or a registered node target
Examples

// 1. remove eventManager add Listener;
var mouseListener1 = cc.eventManager.addListener({
    event: cc.EventListener.MOUSE,
    onMouseDown:  function(keyCode, event){ },
    onMouseUp: function(keyCode, event){ },
    onMouseMove: function () { },
    onMouseScroll: function () { }
}, node);

cc.eventManager.removeListener(mouseListener1);

// 2. remove eventListener create Listener;
var mouseListener2 = cc.EventListener.create({
    event: cc.EventListener.MOUSE,
    onMouseDown:  function(keyCode, event){ },
    onMouseUp: function(keyCode, event){ },
    onMouseMove: function () { },
    onMouseScroll: function () { }
});

cc.eventManager.removeListener(mouseListener2);
removeListeners

Removes all listeners with the same event listener type or removes all listeners of a node.

meta description
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/event-manager/CCEventManager.js:898
Parameters
removeAllListeners

Removes all listeners

meta description
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/event-manager/CCEventManager.js:982
setPriority

Sets listener's priority with fixed value.

meta description
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/event-manager/CCEventManager.js:995
Parameters
setEnabled

Whether to enable dispatching events

meta description
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/event-manager/CCEventManager.js:1025
Parameters
isEnabled

Checks whether dispatching events is enabled

meta description
Returns Boolean
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/event-manager/CCEventManager.js:1035

results matching ""

    No results matching ""