Game Development Reference
In-Depth Information
} else {
this->setRotation( fmodf(this->getRotation(),
-360.0f) );
}
}
2. Here we are saying, if the rocket is not rotating (_rotationOrientation
== ROTATE_NONE ), just move it according to its current _vector . If it is ro-
tating, then use the Cocos2d-x helper rotateByAngle method to find its next
position around its pivot point:
3. The method will rotate any point around a pivot by a certain angle. So we rotate
the rocket's updated position around its pivot (determined by the player) using a
property of Rocket class called _ angularSpeed ; we'll see in a moment how
it gets calculated.
4. Based on whether the rocket is rotating clockwise or counterclockwise, we adjust
its rotation so the rocket will be at a 90 degree angle with the line drawn between
the rocket and its pivot point. Then we change the rocket's movement vector
based on this rotated angle, and we wrap the value of that angle between 0 and
360.
5. Finish up the update method with these lines:
if (_targetRotation > this->getRotation() + 180) {
_targetRotation -= 360;
}
if (_targetRotation < this->getRotation() - 180) {
_targetRotation += 360;
Search WWH ::




Custom Search