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

#include <CUTouchListener.h>

Inheritance diagram for TouchListener:

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 TouchListenercreate ()
 
static TouchListenercreate (EventDispatcher *dispatcher)
 

Public Attributes

std::function< bool(Touch *touch, timestamp_t time)> onTouchBegan
 
std::function< void(Touch *touch, timestamp_t time)> onTouchMoved
 
std::function< void(Touch *touch, timestamp_t time)> onTouchEnded
 
std::function< void(Touch *touch, timestamp_t time)> onTouchCancelled
 
CC_CONSTRUCTOR_ACCESS __pad0__: TouchListener() : _active(false) {} virtual ~TouchListener()
 

Protected Attributes

EventDispatcher * _dispatcher
 
EventListenerTouchOneByOne * _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 EventListenerTouchOneByOne. More importantly,it adds a timestamp to all of the callback functions so that the user can precisely time the callbacks.

While this listener is designed for mobile devices, it will register mouse events as well. It is preferable to MouseListener when full mouse motion is not required, because it is more efficient.

Member Function Documentation

NS_CC_BEGIN TouchListener * TouchListener::create ( )
static

Creates a new input controller for the default dispatcher.

a reference to the default event dispatcher

Returns
An autoreleased touch listener
TouchListener * TouchListener::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 TouchListener::init ( )
inline

Initializes a new input controller for the default dispatcher.

Returns
true if the listener is initialized properly, false otherwise.
bool TouchListener::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 TouchListener::isActive ( ) const
inline

Returns whether this listener is active and receiving events

Returns whether this listener is active and receiving events

void TouchListener::start ( int  priority)

Starts this listener, registering it to receive events.

The listener has fixed priority.

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

Starts this listener, registering it to receive events.

The listener has scene priority.

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

Stops this listener, so that it no longer receives events

Member Data Documentation

bool TouchListener::_active
protected

Whether this listener is active and receiving events

EventDispatcher* TouchListener::_dispatcher
protected

The event dispatching handling input for this controller

EventListenerTouchOneByOne* TouchListener::_touchListener
protected

Listener to process touch events

std::function<bool(Touch* touch, timestamp_t time)> TouchListener::onTouchBegan

Called when a touch first starts

While this interface is designed for single touches, it can handle multitouch events. Look at the id in the touch state for touch identification when multiple touches happen.

Parameters
touchthe touch state
timethe time of the event
Returns
true if the touch is consumed; false otherwise
std::function<void(Touch* touch, timestamp_t time)> TouchListener::onTouchCancelled

Called when a touch is aborted

While this interface is designed for single touches, it can handle multitouch events. Look at the id in the touch state for touch identification when multiple touches happen.

Parameters
touchthe touch state
timethe time of the event
std::function<void(Touch* touch, timestamp_t time)> TouchListener::onTouchEnded

Called when a touch completes

While this interface is designed for single touches, it can handle multitouch events. Look at the id in the touch state for touch identification when multiple touches happen.

Parameters
touchthe touch state
timethe time of the event
std::function<void(Touch* touch, timestamp_t time)> TouchListener::onTouchMoved

Called when a touch moves.

While this interface is designed for single touches, it can handle multitouch events. Look at the id in the touch state for touch identification when multiple touches happen.

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
touchthe touch state
timethe time of the event

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