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

Author Topic: How to use bounding boxes and points?  (Read 1661 times)

0 Members and 1 Guest are viewing this topic.

OrientatedCookie

  • Newbie
  • *
  • Posts: 18
    • View Profile
How to use bounding boxes and points?
« 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();
}



 

AlexAUT

  • Sr. Member
  • ****
  • Posts: 396
    • View Profile
Re: How to use bounding boxes and points?
« Reply #1 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()

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


AlexAUT

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: How to use bounding boxes and points?
« Reply #2 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.
Laurent Gomila - SFML developer