Hello! I'm new to the forums, so excuse me if I'm breaking any rules
I'd like to request help with a little issue I have with the implementation of Box2D in my game.
The problem is that whenever I draw my sprites, I get a box and a player on top of each other for each object on screen. I can see where my code fails, but I have no idea what I should do to make it work properly.
This is my current code:
for (b2Body* BodyIterator = World.GetBodyList(); BodyIterator != 0; BodyIterator = BodyIterator->GetNext()){
if (BodyIterator->GetType() == b2_dynamicBody)
{
box.DrawBox2DBody(window, BodyIterator); // Class details below
player.DrawBox2DBody(window, BodyIterator);
}
}
void Object::DrawBox2DBody(sf::RenderWindow &window, b2Body *BodyIterator)
{
_sprite.setOrigin(sf::Vector2f(_sprite.getTextureRect().width / 2, _sprite.getTextureRect().height / 2));
_sprite.setPosition(SCALE * BodyIterator->GetPosition().x, SCALE * BodyIterator->GetPosition().y);
_sprite.setRotation(BodyIterator->GetAngle() * 180/b2_pi);
window.draw(_sprite);
}
I hope this is enough information. Thanks in advance!
EDIT
i think one solution could be to access each object's body separately so that I can draw them one by one. I tried to do that without sucess. That should work. Right?