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

Author Topic: RectangleShape bug or user error?  (Read 1889 times)

0 Members and 2 Guests are viewing this topic.

Erdrick

  • Jr. Member
  • **
  • Posts: 61
    • View Profile
    • Email
RectangleShape bug or user error?
« 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!
« Last Edit: April 10, 2016, 06:30:48 am by erdrick22 »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: RectangleShape bug or user error?
« Reply #1 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?
Laurent Gomila - SFML developer

Erdrick

  • Jr. Member
  • **
  • Posts: 61
    • View Profile
    • Email
Re: RectangleShape bug or user error?
« Reply #2 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()?




eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11006
    • View Profile
    • development blog
    • Email
AW: RectangleShape bug or user error?
« Reply #3 on: April 10, 2016, 07:17:44 pm »
Changing the position is called a translation.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Erdrick

  • Jr. Member
  • **
  • Posts: 61
    • View Profile
    • Email
Re: RectangleShape bug or user error?
« Reply #4 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.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11006
    • View Profile
    • development blog
    • Email
Re: RectangleShape bug or user error?
« Reply #5 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).
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything