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

Author Topic: Roll over images  (Read 2780 times)

0 Members and 2 Guests are viewing this topic.

totalwar235

  • Newbie
  • *
  • Posts: 11
    • View Profile
Roll over images
« 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.

Oneiros

  • Jr. Member
  • **
  • Posts: 60
    • View Profile
Roll over images
« Reply #1 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)
{
 //...
}

totalwar235

  • Newbie
  • *
  • Posts: 11
    • View Profile
Roll over images
« Reply #2 on: February 19, 2011, 05:51:37 am »
Thanks for that idea. I had no clue GetSubReact even existed

Walker

  • Full Member
  • ***
  • Posts: 181
    • View Profile
Roll over images
« Reply #3 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.

totalwar235

  • Newbie
  • *
  • Posts: 11
    • View Profile
Roll over images
« Reply #4 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?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Roll over images
« Reply #5 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 ;)
Laurent Gomila - SFML developer