Cocos2d-x  v3.11
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Groups
EventDispatcher Class Reference

This class manages event listener subscriptions and event dispatching. More...

Inherits Ref.

Public Member Functions

void addEventListenerWithSceneGraphPriority (EventListener *listener, Node *node)
 Adds a event listener for a specified event with the priority of scene graph. More...
 
local addEventListenerWithSceneGraphPriority ( local listener, local node)
 Adds a event listener for a specified event with the priority of scene graph. More...
 
void addEventListenerWithFixedPriority (EventListener *listener, int fixedPriority)
 Adds a event listener for a specified event with the fixed priority. More...
 
EventListenerCustomaddCustomEventListener (const std::string &eventName, const std::function< void(EventCustom *)> &callback)
 Adds a Custom event listener. More...
 
void removeEventListener (EventListener *listener)
 Remove a listener. More...
 
void removeEventListenersForType (EventListener::Type listenerType)
 Removes all listeners with the same event listener type. More...
 
void removeEventListenersForTarget (Node *target, bool recursive=false)
 Removes all listeners which are associated with the specified target. More...
 
void removeCustomEventListeners (const std::string &customEventName)
 Removes all custom listeners with the same event name. More...
 
void removeAllEventListeners ()
 Removes all event listeners.
 
void pauseEventListenersForTarget (Node *target, bool recursive=false)
 Pauses all listeners which are associated the specified target. More...
 
void resumeEventListenersForTarget (Node *target, bool recursive=false)
 Resumes all listeners which are associated the specified target. More...
 
void setPriority (EventListener *listener, int fixedPriority)
 Sets listener's priority with fixed value. More...
 
void setEnabled (bool isEnabled)
 Whether to enable dispatching events. More...
 
bool isEnabled () const
 Checks whether dispatching events is enabled. More...
 
void dispatchEvent (Event *event)
 Dispatches the event. More...
 
void dispatchCustomEvent (const std::string &eventName, void *optionalUserData=nullptr)
 Dispatches a Custom Event with a event name an optional user data. More...
 
local dispatchCustomEvent ( local eventName, local nullptr)
 Dispatches a Custom Event with a event name an optional user data. More...
 
 EventDispatcher ()
 Constructor of EventDispatcher.
 
 ~EventDispatcher ()
 Destructor of EventDispatcher.
 
- Public Member Functions inherited from Ref
void retain ()
 Retains the ownership. More...
 
local retain ()
 Retains the ownership. More...
 
void 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.
 

Additional Inherited Members

- 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.
 
bool _scriptOwned
 The life of the object is scrolled by the scripting engine. More...
 
local _scriptOwned
 The life of the object is scrolled by the scripting engine. More...
 

Detailed Description

This class manages event listener subscriptions and event dispatching.

The EventListener list is managed in such a way that event listeners can be added and removed even from within an EventListener, while events are being dispatched.

Member Function Documentation

void
addEventListenerWithSceneGraphPriority
( EventListener listener,
Node node 
)

Adds a event listener for a specified event with the priority of scene graph.

The listener of a specified event. The priority of the listener is based on the draw order of this node. The priority of scene graph will be fixed value 0. So the order of listener item in the vector will be ' <0, scene graph (0 priority), >0'.

local
addEventListenerWithSceneGraphPriority
( local  listener,
local  node 
)

Adds a event listener for a specified event with the priority of scene graph.

The listener of a specified event. The priority of the listener is based on the draw order of this node. The priority of scene graph will be fixed value 0. So the order of listener item in the vector will be ' <0, scene graph (0 priority), >0'.

void
addEventListenerWithFixedPriority
( EventListener listener,
int  fixedPriority 
)

Adds a event listener for a specified event with the fixed priority.

The listener of a specified event. The fixed priority of the listener. A lower priority will be called before the ones that have a higher value. 0 priority is forbidden for fixed priority since it's used for scene graph based priority.

local
addEventListenerWithFixedPriority
( local  listener,
local  fixedPriority 
)

Adds a event listener for a specified event with the fixed priority.

The listener of a specified event. The fixed priority of the listener. A lower priority will be called before the ones that have a higher value. 0 priority is forbidden for fixed priority since it's used for scene graph based priority.

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

Adds a Custom event listener.

It will use a fixed priority of 1. A given name of the event. A given callback method that associated the event name. the generated event. In order to remove the event later from the dispather

local addCustomEventListener ( local  eventName,
local  callback 
)

Adds a Custom event listener.

It will use a fixed priority of 1. A given name of the event. A given callback method that associated the event name. the generated event. In order to remove the event later from the dispather

void removeEventListener ( EventListener listener)

Remove a listener.

The specified event listener which needs to be removed.

local removeEventListener ( local  listener)

Remove a listener.

The specified event listener which needs to be removed.

void removeEventListenersForType ( EventListener::Type  listenerType)

Removes all listeners with the same event listener type.

A given event listener type which needs to be removed.

local removeEventListenersForType ( local  listenerType)

Removes all listeners with the same event listener type.

A given event listener type which needs to be removed.

void removeEventListenersForTarget ( Node target,
bool  recursive = false 
)

Removes all listeners which are associated with the specified target.

A given target node. True if remove recursively, the default value is false.

local removeEventListenersForTarget ( local  target,
local  recursive = false 
)

Removes all listeners which are associated with the specified target.

A given target node. True if remove recursively, the default value is false.

void removeCustomEventListeners ( const std::string &  customEventName)

Removes all custom listeners with the same event name.

A given event listener name which needs to be removed.

local removeCustomEventListeners ( local  customEventName)

Removes all custom listeners with the same event name.

A given event listener name which needs to be removed.

void pauseEventListenersForTarget ( Node target,
bool  recursive = false 
)

Pauses all listeners which are associated the specified target.

A given target node. True if pause recursively, the default value is false.

local pauseEventListenersForTarget ( local  target,
local  recursive = false 
)

Pauses all listeners which are associated the specified target.

A given target node. True if pause recursively, the default value is false.

void resumeEventListenersForTarget ( Node target,
bool  recursive = false 
)

Resumes all listeners which are associated the specified target.

A given target node. True if resume recursively, the default value is false.

local resumeEventListenersForTarget ( local  target,
local  recursive = false 
)

Resumes all listeners which are associated the specified target.

A given target node. True if resume recursively, the default value is false.

void setPriority ( EventListener listener,
int  fixedPriority 
)

Sets listener's priority with fixed value.

A given listener. The fixed priority value.

local setPriority ( local  listener,
local  fixedPriority 
)

Sets listener's priority with fixed value.

A given listener. The fixed priority value.

void setEnabled ( bool  isEnabled)

Whether to enable dispatching events.

True if enable dispatching events.

local setEnabled ( local  isEnabled)

Whether to enable dispatching events.

True if enable dispatching events.

bool isEnabled ( ) const

Checks whether dispatching events is enabled.

True if dispatching events is enabled.

local isEnabled ( )

Checks whether dispatching events is enabled.

True if dispatching events is enabled.

void dispatchEvent ( Event event)

Dispatches the event.

Also removes all EventListeners marked for deletion from the event dispatcher list.

The event needs to be dispatched.

local dispatchEvent ( local  event)

Dispatches the event.

Also removes all EventListeners marked for deletion from the event dispatcher list.

The event needs to be dispatched.

void dispatchCustomEvent ( const std::string &  eventName,
void *  optionalUserData = nullptr 
)

Dispatches a Custom Event with a event name an optional user data.

The name of the event which needs to be dispatched. The optional user data, it's a void*, the default value is nullptr.

local dispatchCustomEvent ( local  eventName,
local  optionalUserData = nullptr 
)

Dispatches a Custom Event with a event name an optional user data.

The name of the event which needs to be dispatched. The optional user data, it's a void*, the default value is nullptr.


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