Game Development Reference
In-Depth Information
Time for action - handling touches
Let's go back to GameLayer.cpp and add our game's final touches (pun intended).
1. First we work on our onTouchBegan method:
bool GameLayer::onTouchBegan(Touch* touch, Event*
event) {
if (!_running) {
if (_player->getState() == kPlayerDying) {
_terrain->reset();
_player->reset();
resetGame();
}
return true;
}
If we are not running the game and the _player object died, we reset the game
on touch.
2. Next, if the terrain has not started, insert the following:
if (!_terrain->getStartTerrain()) {
_terrain->setStartTerrain ( true );
return true;
}
Remember that at first the buildings are all the same height and there are no gaps.
Once the player presses the screen, we begin changing that through
setStartTerrain .
3. We finish with:
if (touch) {
if (_player->getState() == kPlayerFalling) {
_player->setFloating (
_player->getFloating() ? false : true );
} else {
Search WWH ::




Custom Search