SFML community forums

Help => Graphics => Topic started by: Jan666 on March 22, 2022, 01:23:05 pm

Title: Touch Button
Post by: Jan666 on March 22, 2022, 01:23:05 pm
Hi i am searching the Code for a simple Exercise, maybe someone can help me. I work with  sf::Touch, let me explain what i need:
I have 2 RectableShapes  and now i want to use one for a button. If i touch the ButtonRectable the Color change by Rectable Nr.2?

Title: Re: Touch Button
Post by: Jan666 on March 23, 2022, 12:45:51 pm
Okay Sometimes is the best when you Help yourself and dont ask in a Dead Forum. So In case someone has the same problem, here is the Solution:

Vector2f buttonSize (300, 300);
Vector2f buttonPosition (100, 800);

RectangleShape Button;
Button.setSize(buttonSize);
Button.setPosition(buttonPosition);

FloatRect buttonTouch (buttonPosition, buttonSize);

if(buttonTouch.contains(Touch::getPosition(0).x, Touch::getPosition(0).y){

    //Set the other rectangle fill with Color
}
Title: Re: Touch Button
Post by: eXpl0it3r on March 23, 2022, 01:09:25 pm
Glad you found a solution, but please work a bit on your attitude...