I am trying to implement chipmunk into my tile based game. I originally tried Box2D but found that the character got stuck on block edges. Currently, when you enter the game, the character starts off at a strange location of (49347, 32395) instead of (385,254). I define my bodies like this:
Code: Select all
void physics_addStaticBodies()
{
for(int i = 0; i < 256; i++)
{
for(int i2 = 0; i2 < 256; i2++)
{
if(tile[i][i2].visible && tile[i][i2].shape == 1)
{
tile[i][i2].body = cpSpaceAddBody(world, cpBodyNew(INFINITY, INFINITY));
cpBodySetPos(tile[i][i2].body, cpv(tile[i][i2].x, tile[i][i2].y));
cpShape *Shape = cpSpaceAddShape(world, cpBoxShapeNew(tile[i][i2].body, blocksize, blocksize));
cpShapeSetFriction(Shape, 0.7);
}
}
}
}
void physics_addDynamicBodies()
{
for(int i = 0; i < characters; i++)
{
if(character[i].visible)
{
character[i].body = cpSpaceAddBody(world, cpBodyNew(1.0f, INFINITY));
cpBodySetPos(character[i].body, cpv(character[i].x, character[i].y));
cpShape *Shape = cpSpaceAddShape(world, cpBoxShapeNew(character[i].body, character[i].width, character[i].height));
cpShapeSetFriction(Shape, 0.7);
}
}
}
Thanks,
James