Hello ,
I ask you a bit of help . I dont understand becouse my size body doesnt match size sprite .That is a bad becouse my collision has no
accuracy
There is attachment here. Any help pls?
Thanks in advance
Ship sprite:
60 x56
Body = idem . I assume 1 meter = 30 pixel
Rock sprite:
39x32
Body = idem . I assume 1 meter = 30 pixel
my code for body
code for rock
[/code]
I ask you a bit of help . I dont understand becouse my size body doesnt match size sprite .That is a bad becouse my collision has no
accuracy
There is attachment here. Any help pls?
Thanks in advance
Ship sprite:
60 x56
Body = idem . I assume 1 meter = 30 pixel
Rock sprite:
39x32
Body = idem . I assume 1 meter = 30 pixel
my code for body
Code:
b2Body * CreateShip(b2World *World, b2BodyType type, sf::Sprite &Shape)
{
b2BodyDef def;
def.type = type;
def.position.Set(13.33f,16.66f ); // Position is 400,500
b2Body* Body = World->CreateBody(&def);
b2PolygonShape pol;
pol.SetAsBox(2.f, 1.86f); // sprite is 60x56
b2FixtureDef fix;
fix.shape = &pol;
fix.density = 1.0f;
fix.friction = .3f;
Body->CreateFixture(&fix);
Shape.SetOrigin(30,28);
Shape.SetPosition(400,500);
return Body;
}
{
b2BodyDef def;
def.type = type;
def.position.Set(13.33f,16.66f ); // Position is 400,500
b2Body* Body = World->CreateBody(&def);
b2PolygonShape pol;
pol.SetAsBox(2.f, 1.86f); // sprite is 60x56
b2FixtureDef fix;
fix.shape = &pol;
fix.density = 1.0f;
fix.friction = .3f;
Body->CreateFixture(&fix);
Shape.SetOrigin(30,28);
Shape.SetPosition(400,500);
return Body;
}
code for rock
Code:
b2Body * CreateRock(b2World *World, b2BodyType type, sf::Sprite &Shape)
{
b2BodyDef def;
def.type = type;
def.position.Set(13.33f, 13.33f); // // Position is 400,400
b2Body* Body = World->CreateBody(&def);
b2PolygonShape pol;
pol.SetAsBox(1.3f, 1.06f); // ---- the sprite is 39x32
b2FixtureDef fix;
fix.shape = &pol;
fix.density = 1.0f;
fix.friction = .3f;
Body->CreateFixture(&fix);
Shape.SetOrigin(19.5f,16.f);
Shape.SetPosition(400,400);
return Body;
}
{
b2BodyDef def;
def.type = type;
def.position.Set(13.33f, 13.33f); // // Position is 400,400
b2Body* Body = World->CreateBody(&def);
b2PolygonShape pol;
pol.SetAsBox(1.3f, 1.06f); // ---- the sprite is 39x32
b2FixtureDef fix;
fix.shape = &pol;
fix.density = 1.0f;
fix.friction = .3f;
Body->CreateFixture(&fix);
Shape.SetOrigin(19.5f,16.f);
Shape.SetPosition(400,400);
return Body;
}
[/code]