Game Development Reference
In-Depth Information
Figure 10-2 . The player's center and circumference nodes
Finding Points on the Circumference of a Circle
Now here's the first problem: positioning the nodes on a circle. The right, left, top, and
bottom nodes are fairly easy, but what about the other ones? An approximation may suf-
fice, but the positions of the nodes should be equally spaced; otherwise, the body won't
roll and rotate evenly. Especially if you want to create a larger body, you may even need
more than eight bodies to form the circumference. So how would you go about determin-
ing the position of bodies (or points) on a circle's circumference?
It turns out that it just involves applying sin and cos to a specific angle, multiplied by the
circle's radius to get the x,y coordinates of a point on the circle. You are going to write a
simple method that prints out the position of a given number of points on a circle, distrib-
uted evenly.
Open SoftBodyDrawNode.m in Xcode. Add the code in Listing 10-1 between the @im-
plementation and @end lines.
Listing 10-1 . Printing positions of points on a circle to the Xcode console
-(void) didLoadFromCCB
{
[self logPointsOnCircleWithRadius:30
origin:CGPointMake(32, 32)
numPoints:8];
}
-(void) logPointsOnCircleWithRadius:(CGFloat)radius
origin:(CGPoint)origin
Search WWH ::




Custom Search