![]() |
Cornell Cocos
Cornell Extensions to Cocos2d
|
#include <CUTouchListener.h>
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 TouchListener * | create () |
static TouchListener * | create (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 |
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.
|
static |
Creates a new input controller for the default dispatcher.
a reference to the default event dispatcher
|
static |
Creates a new input controller for the given dispatcher.
dispatcher | Event handler for callbacks. |
a reference to the event dispatcher
|
inline |
Initializes a new input controller for the default dispatcher.
bool TouchListener::init | ( | EventDispatcher * | dispatcher | ) |
Creates a new input controller for the given dispatcher.
dispatcher | Event handler for callbacks. |
a reference to the event dispatcher
|
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.
priority | The input priority for the listener. |
void TouchListener::start | ( | Node * | node | ) |
Starts this listener, registering it to receive events.
The listener has scene priority.
node | The node for scene priority. |
void TouchListener::stop | ( | ) |
Stops this listener, so that it no longer receives events
|
protected |
Whether this listener is active and receiving events
|
protected |
The event dispatching handling input for this controller
|
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.
touch | the touch state |
time | the time of the event |
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.
touch | the touch state |
time | the 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.
touch | the touch state |
time | the 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.
touch | the touch state |
time | the time of the event |