Skip to content
dgough edited this page Dec 21, 2012 · 10 revisions

By creating your game and extending gameplay::Game, you'll be able to add all the required handlers of input events. Additionally, there are methods on gameplay::Game to poll for the current sensor data. This architecture insulates you, as a developer, from the platform-specific details on handling keyboard, touch and mouse events, and from polling the accelerometer state. The following illustrates overridden methods to handle input events:

#include "gameplay.h"
using namespace gameplay;
class MyGame : public Game
{
    // ...
    void keyEvent(Keyboard::KeyEvent evt, int key);
    void touchEvent(Touch::TouchEvent evt, int x, int y, unsigned int contactIndex);
    bool mouseEvent(Mouse::MouseEvent evt, int x, int y);
    void getAccelerometerValues(float* pitch, float* roll);
};

Handling input events

You have the opportunity, on either desktop platforms or mobile devices, to handle mouse events uniquely from the Game::touchEvent() method (this includes support for a Bluetooth enabled mouse). However, this is not required, and the default implementation of the Game::mouseEvent() method returns false, which means that the user can allow mouse events to be treated automatically as touch events. You can decide to disable multi-touch support for games when you do not want this functionality. You can call Game::setMultiTouch() and pass in false to ensure that the platform treats and handles touch events as single touches.

You can also call Game::displayKeyboard() to show or hide a virtual keyboard for platforms that support it. You'll want to integrate it into points in the game and user interfaces in the game where text input is required. You can call Game::getAccelerometerValues() and pass in pointers to parameters that will be populated with the current sensor values for the accelerometer.

You can also call Game::displayKeyboard() to show or hide a virtual keyboard for platforms that support it. You'll want to integrate it into points in the game and user interfaces in the game where text input is required.

You can call Game::getAccelerometerValues() and pass in pointers to parameters that will be populated with the current sensor values for the accelerometer.

Clone this wiki locally