SFML community forums

Help => Graphics => Topic started by: OrientatedCookie on May 01, 2015, 11:54:19 pm

Title: How to use bounding boxes and points?
Post by: OrientatedCookie on May 01, 2015, 11:54:19 pm
I don't understand the syntax, please correct me. I want to check if a sprite contains a point. and YeS I have read the forums and looked on the wiki.

sf::RectangleShape sprite1box = sprite1.getGlobalBounds();
sf::Vector2f point = (-50, -20);
if (sprite1box.contains(point))
{
window.close();
}



 
Title: Re: How to use bounding boxes and points?
Post by: AlexAUT on May 02, 2015, 12:11:52 am
getGlobalBounds does not return a sf::RectangleShape, instead it returns a sf::Rect<float> (FloatRect).

A quick look at the documentation would have solved your problem:  sf::Sprite::getGlobalBounds() (http://www.sfml-dev.org/documentation/2.2/classsf_1_1Sprite.php#a203d2d8087bfdca2ebc3c0485cdb7409)

The rest of your code looks ok if you change sf::RectangleShape with sf::FloatRect


AlexAUT
Title: Re: How to use bounding boxes and points?
Post by: Laurent on May 02, 2015, 10:20:12 am
Quote
YeS I have read the forums and looked on the wiki.
The primary source of documentation should be the API doc and the tutorials ;) Forum and wiki content is a lot more random.