Game Development Reference
In-Depth Information
The result of the code in Listing 10-2 returns a position relative to the circle's origin. In
other words, the circle is assumed to have its center at position 0x0. Since, in the case of
the player, the circle is centered on the player image at position 32x32, the final x / y co-
ordinates need to be offset by the circle's actual origin position. The NSLog line in List-
ing 10-1 prints only one digit after the comma, as indicated by the %.1f format string.
This is sufficiently accurate for our purposes.
If you run the project now, the desired locations of the points on the circle will be printed
to the Xcode console. See Listing 10-3 .
Listing 10-3 . Output of the code in Listing 10-1 . Points on a circle with radius 30 and
center at 32x32
circumference point 1: {62.0, 32.0} (angle: 360.0)
circumference point 2: {53.2, 10.8} (angle: 315.0)
circumference point 3: {32.0, 2.0} (angle: 270.0)
circumference point 4: {10.8, 10.8} (angle: 225.0)
circumference point 5: {2.0, 32.0} (angle: 180.0)
circumference point 6: {10.8, 53.2} (angle: 135.0)
circumference point 7: {32.0, 62.0} (angle: 90.0)
circumference point 8: {53.2, 53.2} (angle: 45.0)
Note You may be wondering why the radius is 30 rather than 32. It's the same
collision radius as for the rigid player. But, bearing in mind that each circumfer-
ence body represents a circle shape of its own, this will actually increase the
collision radius of the player. If anything, the radius for the positions of the cir-
cumference nodes ought to be less than the previous collision radius. But it
turned out that it's better to compromise. Allowing the player's total size to
grow compared to the previous rigid-body version serves to better illustrate the
design and resulting effects of soft-body physics. The smaller an object is, the
harder it becomes to make it soft and stable.
Positioning Nodes on the Circle's Circumference
Now you can take the positions of Listing 10-3 and apply them to the nodes from right to
top-right in clockwise fashion. The position of the node named right should be 62x32, the
node bottom-right should be at position 53.2x10.8, the node bottom should be at position
Search WWH ::




Custom Search