SFML community forums

Help => Graphics => Topic started by: totalwar235 on February 17, 2011, 11:06:16 pm

Title: Roll over images
Post by: totalwar235 on February 17, 2011, 11:06:16 pm
i want to create roll over images and i have found a way to do this with two "for" functions.  is there a built in way to compare the location of a sprite and a mouse?

i only ask because checking the majority of the screen every time the screen refreshes is a waste of ram.
Title: Roll over images
Post by: Oneiros on February 18, 2011, 09:53:15 am
Hello,

you can use something like this :

Code: [Select]

if (mySprite.GetSubRect().Contains(mousePos.x, mousePos.y)
{
 //...
}
Title: Roll over images
Post by: totalwar235 on February 19, 2011, 05:51:37 am
Thanks for that idea. I had no clue GetSubReact even existed
Title: Roll over images
Post by: Walker on February 20, 2011, 01:15:49 am
I may be incorrect but I think you will have to offset the subrect with the sprites position for this to work. The sprite's subrect is only relative to itself, not the world/screen.
Title: Roll over images
Post by: totalwar235 on February 20, 2011, 08:50:11 pm
Quote
I may be incorrect but I think you will have to offset the subrect with the sprites position for this to work. The sprite's subrect is only relative to itself, not the world/screen.


do you know how to do that?
Title: Roll over images
Post by: Laurent on February 20, 2011, 10:46:46 pm
There's not only the position to take in account, but the rotation and scale as well. The TransformToGlobal function is your friend ;)