1
Graphics / SFML Button
« on: November 13, 2013, 07:54:40 am »
Hi, I made a small Button set since SFML doesnt have a button class directly inputted into it, so I tried to make my own, and I got this, you can add/change/modify it to your liking
Now this may not be the most efficient way to do this, but it worked for me when I tried it.
//Get the position of the Mouse
int MouseX = sf::Mouse::getPosition().x;
int MouseY = sf::Mouse::getPosition().y;
//Create a Shape for the button
sf::RectangleShape button; //Doesnt have to be a rectangle
//Give the Button a color
button.setFillColor(sf::Color::Blue);
//Set size of the button
button.setSize(sf::Vector2f(100,48)); //Make it what ever you like
//Set the position of the button
button.setPosition(200,200);//or where ever you like
//The Fun Stuff!!
if(button.getGlobalBounds().width <=> MouseX
&& button.getGlobalBounds().height <=> MouseY){
//Do What you want to do with the button
button.setFillColor(sf::Color::Green);
}
int MouseX = sf::Mouse::getPosition().x;
int MouseY = sf::Mouse::getPosition().y;
//Create a Shape for the button
sf::RectangleShape button; //Doesnt have to be a rectangle
//Give the Button a color
button.setFillColor(sf::Color::Blue);
//Set size of the button
button.setSize(sf::Vector2f(100,48)); //Make it what ever you like
//Set the position of the button
button.setPosition(200,200);//or where ever you like
//The Fun Stuff!!
if(button.getGlobalBounds().width <=> MouseX
&& button.getGlobalBounds().height <=> MouseY){
//Do What you want to do with the button
button.setFillColor(sf::Color::Green);
}
Now this may not be the most efficient way to do this, but it worked for me when I tried it.