0
\$\begingroup\$
b2BodyDef bd;
    bd.position.Set(1700 / sfdd::SCALE, 150 / sfdd::SCALE);
    bd.type = b2_dynamicBody;
    b2PolygonShape squareShape;
    squareShape.SetAsBox(70 / sfdd::SCALE, 13 / sfdd::SCALE);
    m_body1 = m_world->CreateBody(&bd);
    m_body1->CreateFixture(&squareShape, 100);
    squareShape.SetAsBox(38 / sfdd::SCALE, 16 / sfdd::SCALE,b2Vec2(-54/sfdd::SCALE,-30/sfdd::SCALE),90*DEGTORAD);
    m_body1->CreateFixture(&squareShape, 20);

    squareShape.SetAsBox(30 / sfdd::SCALE, 10 / sfdd::SCALE, b2Vec2(60 / sfdd::SCALE, -20 / sfdd::SCALE), 90 * DEGTORAD);
    m_body1->CreateFixture(&squareShape, 100);
\$\endgroup\$
5
  • \$\begingroup\$ What have you tried? \$\endgroup\$ – Vaillancourt Dec 21 '19 at 12:17
  • \$\begingroup\$ i tried to mess with b2Transform class. Getting shapes from a fixture but no luck. Manual of box2d doesnt even have info about b2Transform class. \$\endgroup\$ – 0x00004 Dec 21 '19 at 20:31
  • \$\begingroup\$ Typically, if you know the size and the offsets of your fixtures, you'll know how to offset the sprites attached to it, using the same offsets as you used for the fixtures. \$\endgroup\$ – Vaillancourt Dec 22 '19 at 12:56
  • \$\begingroup\$ Yes but that would be bad practice. Anyway there s more easier band aid fix that i figured out by now. Just change origin of your sprite until you get the results you need. \$\endgroup\$ – 0x00004 Dec 22 '19 at 13:59
  • \$\begingroup\$ Box2d fixture position \$\endgroup\$ – Vaillancourt Dec 22 '19 at 14:54
1
\$\begingroup\$

Typically the fixtures would approximate the shape of the sprite, they're locked to the body and won't change their transformation. So you just draw the sprite with the body's transformation (position/rotation), and don't care about individual fixtures.

If you really need to draw the fixtures, see the b2World::DrawDebugData() method implementation. It uses user-provided b2Draw object that would perform actual painting of required primitives.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.