Cocos Creator API

0.7.1

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.

Methods

retain ( )

Currently JavaScript Bindings (JSB), in some cases, needs to use retain and release. This is a bug in JSB, and the ugly workaround is to use retain/release. So, these 2 methods were added to be compatible with JSB. This is a hack, and should be removed once JSB fixes the retain/release bug
You will need to retain an object if you created a listener and haven't added it any target node during the same frame.
Otherwise, JSB's native autorelease pool will consider this object a useless one and release it directly,
when you want to use it later, a "Invalid Native Object" error will be raised.
The retain function can increase a reference count for the native object to avoid it being released,
you need to manually invoke release function when you think this object is no longer needed, otherwise, there will be memory learks.
retain and release function call should be paired in developer's game code.

release ( )

Currently JavaScript Bindings (JSB), in some cases, needs to use retain and release. This is a bug in JSB, and the ugly workaround is to use retain/release. So, these 2 methods were added to be compatible with JSB. This is a hack, and should be removed once JSB fixes the retain/release bug
You will need to retain an object if you created a listener and haven't added it any target node during the same frame.
Otherwise, JSB's native autorelease pool will consider this object a useless one and release it directly,
when you want to use it later, a "Invalid Native Object" error will be raised.
The retain function can increase a reference count for the native object to avoid it being released,
you need to manually invoke release function when you think this object is no longer needed, otherwise, there will be memory learks.
retain and release function call should be paired in developer's game code.

create
(
  • argObj
)
EventListener static

Create a EventListener object by json object

name type description
argObj Object

a json object

returns:

type: EventListener

todo: It should be the direct use new

examples:

--------
cc.EventListener.create({

      event: cc.EventListener.TOUCH_ONE_BY_ONE,
      swallowTouches: true,
      onTouchBegan: function (touch, event) {
          //do something
          return true;
      }
   });

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