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

Author Topic: Button  (Read 2114 times)

0 Members and 1 Guest are viewing this topic.

Kevin47

  • Newbie
  • *
  • Posts: 4
    • View Profile
Button
« on: September 22, 2010, 04:29:23 pm »
Hello!
I'm trying to make graphical button (I read tutorials and I tested samples).

Here is my image:


Code example:

Quote
If you click left mouse button and mouse cursor X pos is 100-218 and Y pos is 100-161
{
do something
}



Can someone help? Thanks! :)

Lupinius

  • Jr. Member
  • **
  • Posts: 85
    • View Profile
Button
« Reply #1 on: September 22, 2010, 05:56:00 pm »
What exactly is the problem?

Kevin47

  • Newbie
  • *
  • Posts: 4
    • View Profile
Button
« Reply #2 on: September 22, 2010, 06:45:13 pm »
Quote from: "Lupinius"
What exactly is the problem?


I don't know how to make this.

Finn

  • Jr. Member
  • **
  • Posts: 90
    • View Profile
Button
« Reply #3 on: September 22, 2010, 06:57:23 pm »
Code: [Select]

bool MouseOver(sf::Sprite &Sprite)//returns true if the mouse is over given sf::Sprite
{
float XPos = Sprite.GetPosition().x;//the x position
float YPos = Sprite.GetPosition().y;//the y position
float XSize = Sprite.GetSize().x;//the width
float YSize = Sprite.GetSize().y;//the height

if(MouseX >= XPos && MouseX <= XPos+XSize && MouseY >= YPos && MouseY <= YPos+YSize)
return true;

else
return false;
}