Cornell Cocos
Cornell Extensions to Cocos2d
|
#include <CUKeyboardPoller.h>
Public Member Functions | |
bool | isActive () const |
void | update () |
bool | keyDown (EventKeyboard::KeyCode code) const |
bool | keyPressed (EventKeyboard::KeyCode code) const |
bool | keyReleased (EventKeyboard::KeyCode code) |
int | keyCount () const |
const std::vector< EventKeyboard::KeyCode > | keySet () const |
~KeyboardPoller () | |
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 KeyboardPoller * | getInstance () |
Public Attributes | |
CC_CONSTRUCTOR_ACCESS | __pad0__: KeyboardPoller() |
Protected Attributes | |
EventListenerKeyboard * | _keybdListener |
bool | _active |
std::unordered_set< EventKeyboard::KeyCode, KeyCodeHasher > | _previous |
std::unordered_set< EventKeyboard::KeyCode, KeyCodeHasher > | _current |
std::unordered_map< EventKeyboard::KeyCode, bool, KeyCodeHasher > | _changed |
Static Protected Attributes | |
static KeyboardPoller * | _gKeyboard = nullptr |
Class to providing a polling interface for the Keyboard.
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 keyboard, this class provides a singleton interface. You can start and stop the interface with static methods.
KeyboardPoller::~KeyboardPoller | ( | ) |
Disposes of this input controller, releasing all listeners.
void KeyboardPoller::dispose | ( | ) |
Stops this listener, so that it no longer receives events
|
static |
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 KeyboardPoller::init | ( | int | priority | ) |
Initializes this listener, registering it to receive events.
The listener has fixed priority.
priority | The input priority for the listener. |
void KeyboardPoller::init | ( | Node * | node | ) |
Initializes this listener, registering it to receive events.
The listener has scene priority.
node | The node for scene priority. |
|
inline |
Returns whether this listener is active and receiving events
Returns whether this listener is active and receiving events
|
inline |
Returns the number of keys currently held down.
|
inline |
Returns true if the key is currently held down.
code | the keyboard key to test |
|
inline |
Returns true if the key was pressed this animation frame.
A key press occurs if the key is down this animation frame, but was not down the previous animation frame.
code | the keyboard key to test |
|
inline |
Returns true if the key was released this animation frame.
A key press occurs if the key is up this animation frame, but was not up the previous animation frame.
code | the keyboard key to test |
const std::vector< EventKeyboard::KeyCode > KeyboardPoller::keySet | ( | ) | const |
Returns a list of the keys currently held down.
This list contains the codes for all of the keys currently held down. This list is a copy; modifying it has not effect on the poller.
|
static |
Starts the input processing for this poller.
This method will activate the singleton and assign it a priority. The listener has fixed priority.
priority | The input priority for the keyboard. |
|
static |
Starts the input processing for this poller.
This method will activate the singleton and assign it a priority. The listener has scene priority.
node | The node for scene priority. |
|
static |
Stop the input processing for this input controller.
This will deallocate the singleton, freeing memory.
void KeyboardPoller::update | ( | ) |
Gather the input for the current animation frame.
This method is used to take any cached key events and add them to the poller state. This should be called just before any state queries in the current animation frame.
|
protected |
Whether this listener is active and receiving events
|
protected |
The keys that will change in the next animation frame
|
protected |
The currently pressed keys
|
staticprotected |
Singleton keyboard controller
Initialization of static reference
|
protected |
Listener to process keyboard events
|
protected |
The previously pressed keys