SFML community forums

Help => Graphics => Topic started by: sircuddles on January 29, 2013, 11:01:00 pm

Title: Linking a shape and Rect? [SOLVED]
Post by: sircuddles 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;
Title: Re: Linking a shape and Rect?
Post by: Laurent on January 29, 2013, 11:04:22 pm
objectBounding = objectShape.getGlobalBounds();
Title: Re: Linking a shape and Rect?
Post by: sircuddles 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'.
Title: Re: Linking a shape and Rect?
Post by: eXpl0it3r on January 29, 2013, 11:49:17 pm
That's why there's a documentation (http://www.sfml-dev.org/documentation/2.0/classsf_1_1Sprite.php#a203d2d8087bfdca2ebc3c0485cdb7409)... ::)

getGlobalBounds() returns a sf::FloatRect aka sf::Rect<float>. ;)
Title: Re: Linking a shape and Rect?
Post by: sircuddles 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 :)
Title: Re: Linking a shape and Rect? [SOLVED]
Post by: eXpl0it3r on January 29, 2013, 11:59:56 pm
sf::IntRect and sf::FloatRect are just typedefs for easier usage, see here (https://github.com/SFML/SFML/blob/master/include/SFML/Graphics/Rect.hpp#L190). :)