Time for action – adding the main loop
Let's implement our main update
method.
In
GameLayer.cpp
, inside theupdate
method, add the following lines:if (!_running || _state != kGamePlay) return; if (_lineContainer->getLineType() != LINE_NONE) { _lineContainer->setTip (_rocket->getPosition() ); } if (_rocket->collidedWithSides()) { _lineContainer->setLineType ( LINE_NONE ); } _rocket->update(dt); //update jet particle so it follows rocket if (!_jet->isActive()) _jet->resetSystem(); _jet->setRotation(_rocket->getRotation()); _jet->setPosition(_rocket->getPosition());
We check to see if we are not currently on pause. Then, if there is a line for our ship that we need to show in
_lineContainer
, we update the line'stip
point with the_rocket
current position.We run collision checks between
_rocket
and the screen sides, update the_rocket
sprite, and position and rotate our_jet
particle system to align it with the_rocket
sprite.Next we update
_comet
(its...