-
Notifications
You must be signed in to change notification settings - Fork 360
Home
Shaun Reich edited this page May 7, 2013
·
14 revisions
Welcome to the Chipmunk-Physics wiki!
cpSpace* space = cpSpaceNew();
cpVect gravity = cpv(0, -9.8);
cpSpaceSetGravity(space, gravity);
// each space has its own static body, so in the case of a large tiled world, we'll just add
// shapes to that one body, which means that it's quite cheap. (this is equivalent to Box2D's adding
// multiple fixtures to one body).
cpBB bb = cpBBNew(x, y, x2, y2);
cpShape *tileShape = cpBoxShapeNew2(space->staticBody, bb);
cpShapeSetFriction(tileShape, 0.7);
cpSpaceAddShape(space, tileShape);
And of course you can do that many many times, adding new shapes to the same static body but at different positions.
To delete a tile shape, do use the following:
cpSpaceRemoveShape(space, tileShape);
cpShapeFree(tileShape)
Note that you must remove the shape before freeing it otherwise you will crash.