Cornell Cocos
Cornell Extensions to Cocos2d
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Attributes | List of all members
MultiTouchListener Class Reference

#include <CUMultiTouchListener.h>

Inheritance diagram for MultiTouchListener:

Public Member Functions

void start (int priority)
 
void start (Node *node)
 
void stop ()
 
bool isActive () const
 
bool init ()
 
bool init (EventDispatcher *dispatcher)
 

Static Public Member Functions

static MultiTouchListenercreate ()
 
static MultiTouchListenercreate (EventDispatcher *dispatcher)
 

Public Attributes

std::function< void(const std::vector< Touch * > &touches, timestamp_t time)> onTouchesBegan
 
std::function< void(const std::vector< Touch * > &touches, timestamp_t time)> onTouchesMoved
 
std::function< void(const std::vector< Touch * > &touches, timestamp_t time)> onTouchesEnded
 
std::function< void(const std::vector< Touch * > &touches, timestamp_t time)> onTouchesCancelled
 
CC_CONSTRUCTOR_ACCESS __pad0__: MultiTouchListener() : _active(false) {} virtual ~MultiTouchListener()
 

Protected Attributes

EventDispatcher * _dispatcher
 
EventListenerTouchAllAtOnce * _touchListener
 
bool _active
 

Detailed Description

Class provides a time senstive touch listener.

When created, this class initializes but does not activate a touch listener. You must use the start and stop methods to activate/deactivate the listener. Furthermore, all of the callback functions are originally undefined. They must be defined before this listener performs any useful functionality.

This class simplifies a lot of the overhead for EventListenerTouchAllAtOnce. More importantly,it adds a timestamp to all of the callback functions so that the user can precisely time the callbacks.

While TouchListener can handle multitouch events, this listener is preferred if you are trying to coordinate the touches, such as in gesture recognition.

Member Function Documentation

NS_CC_BEGIN MultiTouchListener * MultiTouchListener::create ( )
static

Creates a new input controller for the default dispatcher.

a reference to the default event dispatcher

Returns
An autoreleased touch listener
MultiTouchListener * MultiTouchListener::create ( EventDispatcher *  dispatcher)
static

Creates a new input controller for the given dispatcher.

Parameters
dispatcherEvent handler for callbacks.

a reference to the event dispatcher

Returns
An autoreleased touch listener
bool MultiTouchListener::init ( )
inline

Initializes a new input controller for the default dispatcher.

Returns
true if the listener is initialized properly, false otherwise.
bool MultiTouchListener::init ( EventDispatcher *  dispatcher)

Creates a new input controller for the given dispatcher.

Parameters
dispatcherEvent handler for callbacks.

a reference to the event dispatcher

Returns
true if the listener is initialized properly, false otherwise.
bool MultiTouchListener::isActive ( ) const
inline

Returns whether this listener is active and receiving events

Returns whether this listener is active and receiving events

void MultiTouchListener::start ( int  priority)

Starts this listener, registering it to receive events.

The listener has fixed priority.

Parameters
priorityThe input priority for the listener.
void MultiTouchListener::start ( Node *  node)

Starts this listener, registering it to receive events.

The listener has scene priority.

Parameters
nodeThe node for scene priority.
void MultiTouchListener::stop ( )

Stops this listener, so that it no longer receives events

Member Data Documentation

bool MultiTouchListener::_active
protected

Whether this listener is active and receiving events

EventDispatcher* MultiTouchListener::_dispatcher
protected

The event dispatching handling input for this controller

EventListenerTouchAllAtOnce* MultiTouchListener::_touchListener
protected

Listener to process touch events

std::function<void(const std::vector<Touch*>& touches, timestamp_t time)> MultiTouchListener::onTouchesBegan

Called when a multitouch event first starts

Parameters
touchesthe collective touch state
timethe time of the event
Returns
true if the touch is consumed; false otherwise
std::function<void(const std::vector<Touch*>& touches, timestamp_t time)> MultiTouchListener::onTouchesCancelled

Called when a multitouch event is aborted

Cancellation occurs when an external event—for example, an incoming phone call—disrupts the current app’s event processing.

Parameters
touchesthe collective touch state
timethe time of the event
std::function<void(const std::vector<Touch*>& touches, timestamp_t time)> MultiTouchListener::onTouchesEnded

Called when a multitouch event completes

Parameters
touchesthe collective touch state
timethe time of the event
std::function<void(const std::vector<Touch*>& touches, timestamp_t time)> MultiTouchListener::onTouchesMoved

Called when a multitouch event moves.

If this event handler runs on a desktop with a mouse, this event will only register if the mouse is moved while a button is held down.

Parameters
touchesthe collective touch state
timethe time of the event

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