Game Development Reference
In-Depth Information
Time for action - handling touches
Time to bring the player to our party:
1. Time to implement our onTouchBegan method. We'll begin by handling the two
game states, intro and game over :
bool GameLayer::onTouchBegan (Touch * touch, Event *
event){
//if game not running, we are seeing either intro
or //gameover
if (!_running) {
//if intro, hide intro message
if (_introMessage->isVisible()) {
_introMessage->setVisible(false);
//if game over, hide game over message
} else if (_gameOverMessage->isVisible()) {
SimpleAudioEngine::getInstance()->stopAllEffects();
_gameOverMessage->setVisible(false);
}
this->resetGame();
return true;
}
2. Here we check to see if the game is not running. If not, we check to see if any of
our messages are visible. If _introMessage is visible, we hide it. If
_gameOverMessage is visible, we stop all current sound effects and hide the
message as well. Then we call a method called resetGame, which will reset all
the game data (energy, score, and countdowns) to their initial values, and set
_running to true .
3. Next we handle the touches. But we only need to handle one each time so we use -
>anyObject() on Set :
Search WWH ::




Custom Search