Game Development Reference
In-Depth Information
CGPoint viewPos
= ccpSub( ccpAdd(target.positionInPoints, offset) ,
viewCenter);
// ... remaining code omitted
}
With this code in place, you are almost ready to try. Before you do so, open GameS-
cene.ccb in SpriteBuilder and select the root node. Remember there are custom properties
that control some of the player behavior. With nine smaller, and thus less massive, bodies
instead of one large body and with the physics forces applied to all nine bodies equally,
the bodies will move far too quickly if you do not change the design parameters. For
_playerNudgeRightVelocity , enter 4 , and a good value to enter for _player-
NudgeUpVelocity is 12 . Check again that _drawPhysicsShapes is set to 1 .
Save and publish. Build and run. You now have. . . well, nine smaller bodies (drawn by
physics debug drawing) bouncing around the level, with the supposed camera following
one of them (the center node). Each body behaves like a player of its own. If any one of
the bodies collides with a saw, it's game over.
Setting Up Vertices and Texture Coordinates
You surely noticed that the player's friendly face is stuck to its original location. It won't
move at all with the bodies. In fact, with the custom draw code you're going to imple-
ment, the sprite position will never change. Instead, you'll simply draw the sprite's texture
at a location determined by the center node and use a shape determined by the circumfer-
ence nodes.
Even though the soft body is anything but a coherent body, that's exactly what will allow
you to see how the drawing code works. It also allows you to see what happens if the soft-
body setup is somehow askew, be it because of an editing mistake or because the soft-
body object has folded in on itself.
Let's start with the unspectacular part first: declaring variables, calling the setup code, and
taking care of deallocation. Update SoftBodyDrawNode.m to the code in Listing 10-8 .
Listing 10-8 . Variables, setup and dealloc of the SoftBodyDrawNode class
#import "SoftBodyDrawNode.h"
@implementation SoftBodyDrawNode
{
Search WWH ::




Custom Search