Game Development Reference
In-Depth Information
_lineContainer->setLineType ( LINE_TEMP );
} else {
_rocket->select(false);
_lineContainer->setLineType ( LINE_NONE );
}
}
4. We'll handle touch moved only if we are using _drawing , which means the
player has pressed on the ship and is now dragging his or her finger across the
screen.
Once the distance between the finger and _rocket is greater than the
_ minLineLength distance we stipulate in game init , then we give a visual
cue to the player by adding a glow around _rocket (_rocket->se-
lect(true)) , and we draw the new line in _lineContainer by passing it
the touch's current position and setting the line type to LINE_TEMP . If the min-
imum length is not reached, we don't show a line and nor do we show the player
selected.
5. Next comes onTouchEnded . There is logic in place already inside our
onTouchEnded method which deals with game states. You should uncomment
the calls to resetGame and add a new else if statement inside the method:
} else if (_state == kGamePaused) {
_pauseBtn->setDisplayFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName
("btn_pause_off.png"));
_paused->setVisible(false);
_state = kGamePlay;
_running = true;
return;
}
6. If the game is paused, we change the texture in the _pauseBtn sprite through
Sprite->setDisplayFrame , and we start running the game again.
7. Now we begin handling the touch. First, we determine whether it's landing on the
Pause button:
if (!_running) return;
if(touch != nullptr) {
Search WWH ::




Custom Search