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

#include <CUAccelerationPoller.h>

Public Member Functions

bool isActive () const
 
const Acceleration & getAcceleration () const
 
void accleromCB (Acceleration *acc, Event *event)
 
 ~AccelerationPoller ()
 
void init (int priority)
 
void init (Node *node)
 
void dispose ()
 

Static Public Member Functions

static void start (int priority)
 
static void start (Node *node)
 
static void stop ()
 
static AccelerationPollergetInstance ()
 

Public Attributes

CC_CONSTRUCTOR_ACCESS __pad0__: AccelerationPoller()
 

Protected Attributes

EventListenerAcceleration * _accelListener
 
Acceleration _acceleration
 
bool _active
 

Static Protected Attributes

static AccelerationPoller_gAcceleration = nullptr
 

Detailed Description

Class to providing a polling interface for the Accelerometer.

Cocos2d decided to make all of its input event-driven. This is a major problem, because it is hard to associate the events with the current animation frame, potentially causing lag. A poller is an alternative input interface that allows us to query the current state of the keyboard when we need it.

Because there is (theoretically) only one accelerometer, this class provides a singleton interface. You can start and stop the interface with static methods.

Constructor & Destructor Documentation

AccelerationPoller::~AccelerationPoller ( )

Disposes of this input controller, releasing all listeners.

Member Function Documentation

void AccelerationPoller::accleromCB ( Acceleration *  acc,
Event *  event 
)

Callback for a change in accelerometer state

Parameters
accThe accelerometer information
eventThe associated event
void AccelerationPoller::dispose ( )

Stops this listener, so that it no longer receives events

const Acceleration& AccelerationPoller::getAcceleration ( ) const
inline

Returns the most recent acceleration value.

Returns
the most recent acceleration value.
AccelerationPoller * AccelerationPoller::getInstance ( )
static

Returns the singleton interface for the acceleration poller.

It is unsafe to make your own acceleration poller. Just use this static method to access the singleton object.

This method will return nullptr if the poller is not yet started.

Returns the singleton interface for the keyboard poller.

It is unsafe to make your own keyboard poller. Just use this static method to access the singleton object.

This method will return nullptr if the poller is not yet started.

void AccelerationPoller::init ( int  priority)

Initializes this listener, registering it to receive events.

The listener has fixed priority.

Parameters
priorityThe input priority for the listener.
void AccelerationPoller::init ( Node *  node)

Initializes this listener, registering it to receive events.

The listener has scene priority.

Parameters
nodeThe node for scene priority.
bool AccelerationPoller::isActive ( ) const
inline

Returns whether this listener is active and receiving events

Returns whether this listener is active and receiving events

void AccelerationPoller::start ( int  priority)
static

Starts the input processing for this poller.

This method will activate the singleton and assign it a priority. The listener has fixed priority.

Parameters
priorityThe input priority for the keyboard.
void AccelerationPoller::start ( Node *  node)
static

Starts the input processing for this poller.

This method will activate the singleton and assign it a priority. The listener has scene priority.

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

Stop the input processing for this input controller.

This will deallocate the singleton, freeing memory.

Member Data Documentation

Acceleration AccelerationPoller::_acceleration
protected

The most recent acceleration value

EventListenerAcceleration* AccelerationPoller::_accelListener
protected

Listener to process keyboard events

bool AccelerationPoller::_active
protected

Whether this listener is active and receiving events

NS_CC_BEGIN AccelerationPoller * AccelerationPoller::_gAcceleration = nullptr
staticprotected

Singleton accleraton controller

Initialization of static reference


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