Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - matiasng37

Pages: [1]
1
General / Re: Help with Box2D (Duplicate sprites)
« on: May 04, 2017, 01:34:36 am »
The problem is that for each body (2) I'm drawing both the box and the player. So I get four of them.

EDIT
I found a not very nice solution. I will improve it and then share it. In case someone else needs it.

2
General / Help with Box2D (Duplicate sprites)
« on: May 03, 2017, 11:27:28 pm »
Hello! I'm new to the forums, so excuse me if I'm breaking any rules  :-X

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:

Quote
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);
                        }
}

Quote
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?

Pages: [1]
anything