Game Development Reference
In-Depth Information
void Game::PointerPressed(float x, float y)
{
// Determine which side of the screen is
being pressed
_sidePressed = y - (m_windowBounds.Height /
2.0f);
}
void Game::PointerReleased(float x, float y)
{
// Determine which side of the screen is
being pressed
_sidePressed = 0;
}
void Game::PointerMoved(float x, float y)
{
// Determine which side of the screen is
being pressed
// if we're already moving
if (_sidePressed != 0)
_sidePressed = y - (m_windowBounds.Height /
2.0f);
}
The given code determines where the pointer is being pressed, and assigns a value
to _sidePressed based on the position on the screen. If the pointer is released,
we need to stop moving so that the value is reset to 0 .
Now that we have this code in place, we just need to move the sprite, and connect
our new methods to the actual event handlers. The Game::Update() method is
where we will be moving the sprite. As mentioned earlier, this is where the game
world is updated and changed before rendering, so we can use this space (and the
timing information provided) to move the sprite, as follows:
void Game::Update(float totalTime, float
deltaTime)
Search WWH ::




Custom Search