Time for action – handling touches
Time to bring the player to our party:
Time to implement our
onTouchBegan
method. We'll begin by handling the two game states,intro
andgame 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; }
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 calledresetGame...