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

Details

Properties

UNKNOWN

The type code of unknown event listener.

meta description
Type Number
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/event-manager/CCEventListener.js:252
KEYBOARD

The type code of keyboard event listener.

meta description
Type Number
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/event-manager/CCEventListener.js:276
ACCELERATION

The type code of acceleration event listener.

meta description
Type Number
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/event-manager/CCEventListener.js:292

Methods

constructor

Constructor

meta description
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/event-manager/CCEventListener.js:44
Parameters
checkAvailable

Checks whether the listener is available.

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

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

meta description
Returns EventListener
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/event-manager/CCEventListener.js:183
setEnabled

Enables or disables the listener

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

Checks whether the listener is enabled

meta description
Returns Boolean
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/event-manager/CCEventListener.js:207
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 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/event-manager/CCEventListener.js:453
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 ""