Cocos Creator API

1.3.0

Cocos Creator is a highly customizable game development tool that utilizes the power of cocos2d-x.

eventManager

: 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.

:

// Add KEYBOARD EventListener To StatusLabel.
cc.eventManager.addListener({
    event: cc.EventListener.KEYBOARD,
    onKeyPressed:  function(keyCode, event){
        var label = event.getCurrentTarget();
        label.setString("Key " + keyCode.toString() + " was pressed!");
    },
    onKeyReleased: function(keyCode, event){
        var label = event.getCurrentTarget();
        label.setString("Key " + keyCode.toString() + " was released!");
    }
}, statusLabel);

// Create ACCELERATION EventListener To Sprite.
cc.eventManager.addListener({
    event: cc.EventListener.ACCELERATION,
    callback: function(acc, event){
        //Here processing logic.
    }
}, sprite);

pauseTarget
(
  • node
  • recursive
)

Pauses all listeners which are associated the specified target.

node Node
recursive Boolean

resumeTarget
(
  • node
  • recursive
)

Resumes all listeners which are associated the specified target.

node Node
recursive Boolean

addListener
(
  • listener
  • nodeOrPriority
)
EventListener

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.

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.

:

: EventListener

Return the listener. Needed in order to remove the event from the dispatcher.

removeListener
(
  • listener
)

Remove a listener.

listener EventListener

an event listener or a registered node target

:


// 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
(
  • listenerType
  • recursive
)

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

listenerType Number | Node

listenerType or a node

recursive Boolean

removeAllListeners ( )

Removes all listeners

setPriority
(
  • listener
  • fixedPriority
)

Sets listener's priority with fixed value.

listener EventListener

Constructor

fixedPriority Number

setEnabled
(
  • enabled
)

Whether to enable dispatching events

enabled Boolean

isEnabled ( ) Boolean

Checks whether dispatching events is enabled

:

There are no methods that match your current filter settings. You can change your filter settings in the index section on this page. index