Using ccp helper methods
In the example of Rocket Through, the game we developed in Chapter 5, On the Line – Rocket Through, we used vectors to describe movement, and now I want to show you the logic behind some of the methods we used to handle vector operations and what they mean.
Rotating the rocket around a point
Let's start, as an example, with the rocket sprite moving with a vector of (5, 0):
We then draw a line from the rocket, say from point A to point B:
Now we want the rocket to rotate around point B. So how can we change the rocket's vector to accomplish that? With Cocos2d-x, we can use the helper point method rotateByAngle
to rotate a point around any other point. In this case, we rotate the rocket's position point around point B by a certain angle.
But here's a question – in which direction should the rocket rotate?
By looking at this figure, you know that the rocket should rotate clockwise, since it's moving towards the right. But programmatically...