Cocos Creator API

1.0.0

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

EventListener

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.

Properties

UNKNOWN Number static

The type code of unknown event listener.

KEYBOARD Number static

The type code of keyboard event listener.

ACCELERATION Number static

The type code of focus event listener.

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

Methods

EventListener
(
  • type
  • listenerID
  • callback
)
EventListner

Constructor

name type description
type Number
listenerID Number
callback Number

returns:

type: EventListner

checkAvailable ( ) Boolean

Checks whether the listener is available.

returns:

type: Boolean

clone ( ) EventListener

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

returns:

setEnabled
(
  • enabled
)

Enables or disables the listener

name type description
enabled Boolean

isEnabled ( ) Boolean

Checks whether the listener is enabled

returns:

type: Boolean

create
(
  • argObj
)
EventListener static

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.

name type description
argObj Object

a json object

returns:

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);
    }
});

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