Cocos2d-x  v3.17
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Groups Pages
EventListenerCustom Class Reference

Custom event listener. More...

Inherits EventListener.

Inherited by EventListenerPhysicsContact.

Public Member Functions

virtual bool checkAvailable () override
 Overrides.
 
var checkAvailable ()
 Overrides.
 
local checkAvailable ()
 Overrides.
 
virtual EventListenerCustomclone () override
 Clones the listener, its subclasses have to override this method.
 
local clone ()
 Clones the listener, its subclasses have to override this method.
 
- Public Member Functions inherited from EventListener
virtual ~EventListener ()
 Destructor.
 
local ~EventListener ()
 Destructor.
 
void setEnabled (bool enabled)
 Enables or disables the listener. More...
 
local setEnabled ( local enabled)
 Enables or disables the listener. More...
 
bool isEnabled () const
 Checks whether the listener is enabled. More...
 
local isEnabled ()
 Checks whether the listener is enabled. More...
 
- Public Member Functions inherited from Ref
void retain ()
 Retains the ownership. More...
 
void release ()
 Releases the ownership immediately. More...
 
local release ()
 Releases the ownership immediately. More...
 
Refautorelease ()
 Releases the ownership sometime soon automatically. More...
 
unsigned int getReferenceCount () const
 Returns the Ref's current reference count. More...
 
local getReferenceCount ()
 Returns the Ref's current reference count. More...
 
virtual ~Ref ()
 Destructor. More...
 

Static Public Member Functions

static EventListenerCustomcreate (const std::string &eventName, const std::function< void(EventCustom *)> &callback)
 Creates an event listener with type and callback. More...
 
local create ( local eventName, local callback)
 Creates an event listener with type and callback. More...
 

Protected Member Functions

 EventListenerCustom ()
 Constructor.
 
 EventListenerCustom ()
 Constructor.
 
 EventListenerCustom ()
 Constructor.
 
bool init (const ListenerID &listenerId, const std::function< void(EventCustom *)> &callback)
 Initializes event with type and callback function.
 
var init ( var listenerId, var callback)
 Initializes event with type and callback function.
 
local init ( local listenerId, local callback)
 Initializes event with type and callback function.
 
- Protected Member Functions inherited from EventListener
 EventListener ()
 Constructor. More...
 
bool init (Type t, const ListenerID &listenerID, const std::function< void(Event *)> &callback)
 Initializes event with type and callback function. More...
 
local init ( local t, local listenerID, local callback)
 Initializes event with type and callback function. More...
 

Additional Inherited Members

- Public Types inherited from EventListener
enum  Type
 Type Event type. More...
 
- Public Attributes inherited from Ref
unsigned int _ID
 object id, ScriptSupport need public _ID
 
local _ID
 object id, ScriptSupport need public _ID
 
int _luaID
 Lua reference id.
 
local _luaID
 Lua reference id.
 
void * _scriptObject
 scriptObject, support for swift
 
local _scriptObject
 scriptObject, support for swift
 
bool _rooted
 When true, it means that the object was already rooted.
 
local _rooted
 When true, it means that the object was already rooted.
 

Detailed Description

Custom event listener.

Usage:
auto dispatcher = Director::getInstance()->getEventDispatcher();
Adds a listener:
auto callback = [](EventCustom* event){ do_some_thing(); };
auto listener = EventListenerCustom::create(callback);
dispatcher->addEventListenerWithSceneGraphPriority(listener, one_node);
Dispatches a custom event:
EventCustom event("your_event_type");
dispatcher->dispatchEvent(&event);
Removes a listener
dispatcher->removeEventListener(listener);

Member Function Documentation

static EventListenerCustom* create ( const std::string &  eventName,
const std::function< void(EventCustom *)> &  callback 
)
static

Creates an event listener with type and callback.

Parameters
eventNameThe type of the event.
callbackThe callback function when the specified event was emitted.
Returns
An autoreleased EventListenerCustom object.
var create ( var  eventName,
var  callback 
)
static

Creates an event listener with type and callback.

Parameters
eventNameThe type of the event.
callbackThe callback function when the specified event was emitted.
Returns
An autoreleased EventListenerCustom object.
local create ( local  eventName,
local  callback 
)
static

Creates an event listener with type and callback.

Parameters
eventNameThe type of the event.
callbackThe callback function when the specified event was emitted.
Returns
An autoreleased EventListenerCustom object.

The documentation for this class was generated from the following file: