SFML community forums

Help => Graphics => Topic started by: LucasShadow on May 27, 2012, 02:45:05 am

Title: Understanding .getGlobalBounds().contains
Post by: LucasShadow 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.
Title: Re: Understanding .getGlobalBounds().contains
Post by: Laurent 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.