EventListener Class

Module: cc

The base class of event listener.
If you need custom listener which with different callback, you need to inherit this class.
For instance, you could refer to EventListenerAcceleration, EventListenerKeyboard,
EventListenerTouchOneByOne, EventListenerCustom.

Index

Properties
  • UNKNOWN Number The type code of unknown event listener.
  • KEYBOARD Number The type code of keyboard event listener.
  • ACCELERATION Number The type code of acceleration event listener.
Methods
  • constructor Constructor
  • checkAvailable Checks whether the listener is available.
  • clone Clones the listener, its subclasses have to override this method.
  • setEnabled Enables or disables the listener
  • isEnabled Checks whether the listener is enabled
  • create Create a EventListener object with configuration including the event type, handlers and other parameters.

Details

Properties

UNKNOWN

The type code of unknown event listener.

meta description
Type Number
Defined in cocos2d/core/event-manager/CCEventListener.js:253
KEYBOARD

The type code of keyboard event listener.

meta description
Type Number
Defined in cocos2d/core/event-manager/CCEventListener.js:277
ACCELERATION

The type code of acceleration event listener.

meta description
Type Number
Defined in cocos2d/core/event-manager/CCEventListener.js:293

Methods

constructor

Constructor

meta description
Defined in cocos2d/core/event-manager/CCEventListener.js:45
Parameters
checkAvailable

Checks whether the listener is available.

meta description
Returns Boolean
Defined in cocos2d/core/event-manager/CCEventListener.js:174
clone

Clones the listener, its subclasses have to override this method.

meta description
Returns EventListener
Defined in cocos2d/core/event-manager/CCEventListener.js:184
setEnabled

Enables or disables the listener

meta description
Defined in cocos2d/core/event-manager/CCEventListener.js:194
Parameters
isEnabled

Checks whether the listener is enabled

meta description
Returns Boolean
Defined in cocos2d/core/event-manager/CCEventListener.js:208
create

Create a EventListener object with configuration including the event type, handlers and other parameters. In handlers, this refer to the event listener object itself. You can also pass custom parameters in the configuration object, all custom parameters will be polyfilled into the event listener object and can be accessed in handlers.

meta description
Returns EventListener
Defined in cocos2d/core/event-manager/CCEventListener.js:454
Parameters
Examples
// Create KEYBOARD EventListener.
cc.EventListener.create({
    event: cc.EventListener.KEYBOARD,
    onKeyPressed: function (keyCode, event) {
        cc.log('pressed key: ' + keyCode);
    },
    onKeyReleased: function (keyCode, event) {
        cc.log('released key: ' + keyCode);
    }
});

// Create ACCELERATION EventListener.
cc.EventListener.create({
    event: cc.EventListener.ACCELERATION,
    callback: function (acc, event) {
        cc.log('acc: ' + keyCode);
    }
});

results matching ""

    No results matching ""