Game Development Reference
In-Depth Information
Point tap = touch->getLocation();
if (_pauseBtn->getBoundingBox().containsPoint(tap))
{
_paused->setVisible(true);
_state = kGamePaused;
_pauseBtn->setDisplayFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName
("btn_pause_on.png"));
_running = false;
return;
}
}
8. If so, we change the game state to
kGamePaused
, change the texture on the
_pauseBtn
sprite (by retrieving another sprite frame from
SpriteFrameCache
), stop running the game (pausing it), and return from the
function.
9. We can finally do something about the rocket ship. So, continuing inside the same
if(touch != nullptr) {
conditional seen previously, add these lines:
_drawing = false;
_rocket->select(false);
if (_lineContainer->getLineType() == LINE_TEMP) {
_lineContainer->setPivot (tap);
_lineContainer->setLineLength (
_rocket->getPosition().distance( tap ) );
_rocket->setPivot (tap);
10. We start by deselecting the
_rocket
sprite, and then we check whether we are
currently showing a temporary line in
_lineContainer
. If we are, this means
we can go ahead and create our new pivot point with the player's released touch.
We pass this information to
_lineContainer
with our
setPivot
method,
along with the line length. The
_rocket
sprite also receives the pivot point in-
formation.
Then, things get hairy! The
_rocket
sprite is moving at a pixel-based speed.
Once
_rocket
starts rotating, it will move at an angular-based speed through
Point.rotateByAngle
. So the following lines are added to translate the
_rocket
current pixel-based speed into angular speed: