Cocos Creator API

1.3.0

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

SystemEvent

The System event, it currently supports the key events and accelerometer events

on
(
  • type
  • callback
  • target
  • useCapture
)
Function

Register an callback of a specific event type on the EventTarget. This method is merely an alias to addEventListener.

type String

A string representing the event type to listen for.

callback Function

The callback that will be invoked when the event is dispatched. The callback is ignored if it is a duplicate (the callbacks are unique).

target Object

The target to invoke the callback, can be null

useCapture Boolean

When set to true, the capture argument prevents callback from being invoked when the event's eventPhase attribute value is BUBBLING_PHASE. When false, callback will NOT be invoked when event's eventPhase attribute value is CAPTURING_PHASE. Either way, callback will be invoked when event's eventPhase attribute value is AT_TARGET.

:

: Function

Just returns the incoming callback so you can save the anonymous function easier.

:

node.on(cc.Node.EventType.TOUCH_END, function (event) {
    cc.log("this is callback");
}, node);

off
(
  • type
  • callback
  • target
  • useCapture
)

Removes the callback previously registered with the same type, callback, target and or useCapture. This method is merely an alias to removeEventListener.

type String

A string representing the event type being removed.

callback Function

The callback to remove.

target Object

The target to invoke the callback, if it's not given, only callback without target will be removed

useCapture Boolean

Specifies whether the callback being removed was registered as a capturing callback or not. If not specified, useCapture defaults to false. If a callback was registered twice, one with capture and one without, each must be removed separately. Removal of a capturing callback does not affect a non-capturing version of the same listener, and vice versa.

:

// register touchEnd eventListener
var touchEnd = node.on(cc.Node.EventType.TOUCH_END, function (event) {
    cc.log("this is callback");
}, node);
// remove touchEnd eventListener
node.off(cc.Node.EventType.TOUCH_END, touchEnd, node);

targetOff
(
  • target
)

Removes all callbacks previously registered with the same target.

target Object

The target to be searched for all related callbacks

once
(
  • type
  • callback
  • target
  • useCapture
)

Register an callback of a specific event type on the EventTarget, the callback will remove itself after the first time it is triggered.

type String

A string representing the event type to listen for.

callback Function

The callback that will be invoked when the event is dispatched. The callback is ignored if it is a duplicate (the callbacks are unique).

target Object

The target to invoke the callback, can be null

useCapture Boolean

When set to true, the capture argument prevents callback from being invoked when the event's eventPhase attribute value is BUBBLING_PHASE. When false, callback will NOT be invoked when event's eventPhase attribute value is CAPTURING_PHASE. Either way, callback will be invoked when event's eventPhase attribute value is AT_TARGET.

:

node.once(cc.Node.EventType.TOUCH_END, function (event) {
    cc.log("this is callback");
}, node);

dispatchEvent
(
  • event
)

Dispatches an event into the event flow. The event target is the EventTarget object upon which the dispatchEvent() method is called.

event Event

The Event object that is dispatched into the event flow

emit
(
  • message
  • [detail ]
)

Send an event to this object directly, this method will not propagate the event to any other objects. The event will be created from the supplied message, you can get the "detail" argument from event.detail.

message String

the message to send

detail optional Any

whatever argument the message needs

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