Game Development Reference
In-Depth Information
The code isn't complex, but we need to prepare the
Game
class before we can hook
everything up and have working touch and mouse input.
In the
Game.h
file, we need to add three methods and two variables. The three meth-
ods will be called by the pointer events in the
GameApplication
class, and the first
variable will track the direction we are currently moving in, while the final variable will
define the speed of the player ship.
Inside the private section of the
Game
class, you need to add the following:
int _sidePressed;
float _playerSpeed;
Add the following code in the public section of the
Game
class:
void PointerPressed(float x, float y);
void PointerReleased(float x, float y);
void PointerMoved(float x, float y);
Here you can see how we will use the
_sidePressed
integer to define the way the
player ship moves. If the player presses on the top-half of the screen, the integer will
be set to
-1
, which will move the ship to the top of the screen, and for the bottom-half
of the screen the opposite happens. This means that we can prevent the ship from
moving by setting the
_sidePressed
to
0
, as shown in the following code snippet: