Game Development Reference
In-Depth Information
Notice how Chipmunk can use the same CGPoint structure used in the iPhone SDK.
Chipmunk internally uses a structure called cpVect , but in cocos2d you can use both
interchangeably. I use a CGPoint to set the gravity to −100, which means downward
acceleration that's roughly the same as that used in the Box2D project. You'll also
commonly see the method ccp , which is identical to CGPointMake .
Boxing-In the Boxes
To keep all the boxes within the boundaries of the screen, you need to create a static
body whose shape defines the screen area. You do this in the second part of the
initPhysics method, shown in Listing 12-9 .
Listing 12-9. Creating the Screen Border Collisions
-(void) initPhysics
CGSize screenSize = [CCDirector sharedDirector].winSize;
float boxWidth = screenSize.width;
float boxHeight = screenSize.height;
// bottom
walls[0] = cpSegmentShapeNew(space-> staticBody, ccp(0, 0), ←
ccp(boxWidth, 0), 0.0f);
// top
walls[1] = cpSegmentShapeNew(space-> staticBody, ccp(0, boxHeight), ←
ccp(boxWidth, boxHeight), 0.0f);
// left
walls[2] = cpSegmentShapeNew(space-> staticBody, ccp(0, 0), ←
ccp(0, boxHeight), 0.0f);
// right
walls[3] = cpSegmentShapeNew(space-> staticBody, ccp(boxWidth, 0), ←
ccp(boxWidth, boxHeight), 0.0f);
for (int i = 0; i < 4; i++)
walls[i]-> e = 1.0f;
Search Nedrilad ::

Custom Search