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

Author Topic: Understanding .getGlobalBounds().contains  (Read 8791 times)

0 Members and 1 Guest are viewing this topic.

LucasShadow

  • Jr. Member
  • **
  • Posts: 52
    • View Profile
Understanding .getGlobalBounds().contains
« on: May 27, 2012, 02:45:05 am »
What is strange is that the following works:

if(Sprite1.getGlobalBounds().intersects(Sprite2.getGlobalBounds())) {//Do something}
 

But not something like:

if(Sprite1.getGlobalBounds().contains(Sprite2.getGlobalBounds())) {//Do something}
 

But get the error:
no matching function for call to 'sf::Rect<float>::contains(sf::FloatRect)'

Am I using the contain function incorrectly? And does the contain function just look for Sprite2 being within Sprite1 or does it also look for intersecting?  I ask because I want to have an if statement that turns true if a sprite is within or intersecting another sprite.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Understanding .getGlobalBounds().contains
« Reply #1 on: May 27, 2012, 09:28:10 am »
Quote
Am I using the contain function incorrectly?
Yes, and you would figure out why if you looked at the doc, or at least at the function prototype ;)

Quote
And does the contain function just look for Sprite2 being within Sprite1 or does it also look for intersecting?
intersects also works if r1 is completely inside r2.
Laurent Gomila - SFML developer