SFML community forums

Help => Graphics => Topic started by: Erdrick on April 10, 2016, 06:28:16 am

Title: RectangleShape bug or user error?
Post by: Erdrick on April 10, 2016, 06:28:16 am
Hi,

I found something odd about RectangleShape that I'm not sure if I should report as a bug.

After calling setSize and setPosition (example below)

        sf::RectangleShape m_healthbar;

        m_healthbar.setSize(sf::Vector2f(m_bounding_box_width * .7f, m_bounding_box.getSize().y * .1f));
        m_healthbar.setPosition(m_xpos +
                (m_bounding_box_width * .025f) +
                (m_healthbar_label_text.getLocalBounds().width) +
                10
                , m_ypos + (m_bounding_box_height * .025f) + m_font_size + 5);

        auto dbx = m_healthbar.getPosition().x;         // This returns 1620.59998, which is what I want
        auto dby = m_healthbar.getPosition().y;         // This returns  151.00000, which is what I want
        auto dbl = m_healthbar.getLocalBounds();        // This returns left and top each as 0, seems wrong?
        auto dbg = m_healthbar.getGlobalBounds();       // This returns left as 1620.59998
                                                           //and top as 151.00000, which is perfect

 

I don't understand why getLocalBounds is returning left and top each as 0.  Later in the code I tried to use getLocalBounds to get the position of the shape and it didn't work because it was returning 0 for left and top.  After switching to getGlobalBounds it started working the way I wanted.

Thank you!
Title: Re: RectangleShape bug or user error?
Post by: Laurent on April 10, 2016, 08:53:15 am
And what exactly would you expect? Have you read the documentation of the getLocalBounds function? Do you understand the difference between local and global bounds?
Title: Re: RectangleShape bug or user error?
Post by: Erdrick on April 10, 2016, 06:49:54 pm
Hi,

I did read the documentation before posting but I was thinking that I did not translate, rotate, or scale the entity. 

Maybe I did in fact translate the entity because I called setPosition()?



Title: AW: RectangleShape bug or user error?
Post by: eXpl0it3r on April 10, 2016, 07:17:44 pm
Changing the position is called a translation.
Title: Re: RectangleShape bug or user error?
Post by: Erdrick on April 10, 2016, 10:12:33 pm
Thank you both, I guess the confusion is that I was only "setting" the initial position and not calling "move" I thought it would be part of the local bounds.

I can work with this knowledge of how it works going forward.
Title: Re: RectangleShape bug or user error?
Post by: eXpl0it3r on April 10, 2016, 10:18:10 pm
local is always local to the object, e.g. think of your car, no matter where you parked it, the car engine will always be located at the same place inside your car, while it might be at totally different coordinates in the world (global).