Original Post
I'd love to ask this on the official Chipmunk physics forums, but I can't get a verification email for my forum registration over there :( Does anyone have experience with the Chipmunk 2D physics engine? I am trying to create a level editor for my game that uses Chipmunk, but I can't for the life of me figure out how to "turn off" gravity and restart it. My goal is: - The editor starts with no gravity. Levels are edited this way. - "Play" is pressed, and gravity kicks in. Level is tested this way. - "Stop" button is pressed, and gravity goes back to zero and the level is reloaded, for editing again. The problem is every time I press play, the gravity seems to increase as shapes fall incredibly fast. Here is how I start gravity: Here's how I remove shapes and stop gravity: It all appears to work, but every time I call the stop function, and then the start function everything falls faster. I can't narrow it down to gravity increasing or mass increasing (though I'm removing all the shapes!). Any clue? Is there some kind of cpShutdownChipmunk function? My only other option is to have two separate apps, a level editor and a level tester - which would be much less productive.
// Yes, cpInitChipmunk() is called before any of this.
void State_Playing::StartGravity()
{
g_pSpace = cpSpaceNew();
g_pSpace->gravity = cpv(0, 0);
g_pSpace->elasticIterations = 5;
SetTimer(NULL, 1, 1.0f / 60.0f, TimerProc);
}
void State_Playing::StopGravity()
{
// all Block's deconstructors called here...
cpSpaceDestroy(g_pSpaceNew);
g_pSpace = cpSpaceNew();
g_pSpace->gravity = cpv(0, 0);
g_pSpace->elasticIterations = 5;
}
// Block deconstructor
Block::~Block()
{
// Free shape
if(fixed)
cpSpaceRemoveStaticShape(space, shape);
else
cpSpaceRemoveShape(space, shape);
// Free body
cpSpaceRemoveBody(space, body);
// Free sprite
delete sprite;
}