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

Author Topic: Linking a shape and Rect? [SOLVED]  (Read 1718 times)

0 Members and 1 Guest are viewing this topic.

sircuddles

  • Newbie
  • *
  • Posts: 10
    • View Profile
Linking a shape and Rect? [SOLVED]
« on: January 29, 2013, 11:01:00 pm »
Apologies in advance because I'm fairly sure this question has a simple answer, I'm just too noob to find it.

I'm using primitives to make a Breakout clone and I'd like to use sf::Rect<int>'s intersect() for all my collision detection, so each object in the game will have an sf::Rect<int> that acts as it's bounding box.  Each object also has an sf::RectangleShape to represent the actual object on screen.

Is there an easy way to keep these two linked?  For example, if I move the object is there an easier way than this?

objectShape.setPosition(x, y);
objectBounding.top = x;
objectBounding.left = y;
« Last Edit: January 29, 2013, 11:57:14 pm by sircuddles »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Linking a shape and Rect?
« Reply #1 on: January 29, 2013, 11:04:22 pm »
objectBounding = objectShape.getGlobalBounds();
Laurent Gomila - SFML developer

sircuddles

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: Linking a shape and Rect?
« Reply #2 on: January 29, 2013, 11:38:10 pm »
sf::RectangleShape p1Shape;
sf::Rect<int> p1BoundingBox;
p1BoundingBox = p1Shape.getGlobalBounds();

Results in 'no operator "=" matches these operands'.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: Linking a shape and Rect?
« Reply #3 on: January 29, 2013, 11:49:17 pm »
That's why there's a documentation... ::)

getGlobalBounds() returns a sf::FloatRect aka sf::Rect<float>. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

sircuddles

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: Linking a shape and Rect?
« Reply #4 on: January 29, 2013, 11:57:04 pm »
Ahhhh, I gotcha.  I didn't know sf::FloatRect was sf::Rect<float>, so that part had me confused.

Thank you both :)

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: Linking a shape and Rect? [SOLVED]
« Reply #5 on: January 29, 2013, 11:59:56 pm »
sf::IntRect and sf::FloatRect are just typedefs for easier usage, see here. :)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/