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

Author Topic: Stop looping when touch is holding  (Read 1149 times)

0 Members and 1 Guest are viewing this topic.

Jan666

  • Jr. Member
  • **
  • Posts: 64
    • View Profile
Stop looping when touch is holding
« on: October 12, 2022, 12:59:07 pm »
Hello,
I need to fix following:
I have an animation that play when i Touch a Button. But its looping when i hold the touch on my Button. I dont wanna that, the animation should play once and should not depends how long i hold the touch. I find answers with Keys but i need to  know with Touch functions, there are not many to find in the net.
Here is my code piece:
if(animation == true){
if(animationClock.getElapsedTime().asSeconds() > 0.1)
{
animRec.x ++;
if(animRec.x * 103 >= animationTexture.getSize().x)
animRec.x = 0;

animationClock.restart();
}
}

FloatRect buttonRect = animationSprite.getGlobalBounds();




// the Touch is pressed the button
if(buttonRect.contains(worldPos)){

        animation = true;      
       

}
else
{

if(animRec.x * 412<= animationTexture.getSize().x)
{
        animation = false;     
}
}
 

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10801
    • View Profile
    • development blog
    • Email
Re: Stop looping when touch is holding
« Reply #1 on: October 12, 2022, 01:24:23 pm »
See the event tutorial on how to react to mouse or key input: https://www.sfml-dev.org/tutorials/2.5/window-events.php

Not quite sure I understood what you want, but you can just stop the animation if you get a mouse button pressed (or released) event and the mouse position is inside the button
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Jan666

  • Jr. Member
  • **
  • Posts: 64
    • View Profile
Re: Stop looping when touch is holding
« Reply #2 on: October 12, 2022, 02:49:34 pm »
I uesed Touch on mobile Phone, is  sf::Event::KeyPressed: equal to Event::TouchBegan? Need one input when press/ touch button, and stop looping when hold button

Jan666

  • Jr. Member
  • **
  • Posts: 64
    • View Profile
Re: Stop looping when touch is holding
« Reply #3 on: October 12, 2022, 02:53:54 pm »
Why is there no Touch examples on the "Events explained" tutorials?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10801
    • View Profile
    • development blog
    • Email
Re: Stop looping when touch is holding
« Reply #4 on: October 13, 2022, 08:54:46 am »
Touch is only implemented for mobile platforms so far and we haven't officially documented mobile functionality yet.

Yes, I'd say TouchBegan is like KeyPressed
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Jan666

  • Jr. Member
  • **
  • Posts: 64
    • View Profile
Re: Stop looping when touch is holding
« Reply #5 on: October 14, 2022, 12:01:25 am »
Exist there something like this -> window.setKeyRepeatEnabled(false) for Touch?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10801
    • View Profile
    • development blog
    • Email
Re: Stop looping when touch is holding
« Reply #6 on: October 14, 2022, 12:37:08 pm »
No, there isn't, you'll have to track the current state yourself.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/