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

Author Topic: Touch Button  (Read 1252 times)

0 Members and 1 Guest are viewing this topic.

Jan666

  • Jr. Member
  • **
  • Posts: 64
    • View Profile
Touch Button
« 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?


Jan666

  • Jr. Member
  • **
  • Posts: 64
    • View Profile
Re: Touch Button
« Reply #1 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
}

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10827
    • View Profile
    • development blog
    • Email
Re: Touch Button
« Reply #2 on: March 23, 2022, 01:09:25 pm »
Glad you found a solution, but please work a bit on your attitude...
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/