SFML community forums

Help => Graphics => Topic started by: Jan666 on October 12, 2022, 12:59:07 pm

Title: Stop looping when touch is holding
Post by: Jan666 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;     
}
}
 
Title: Re: Stop looping when touch is holding
Post by: eXpl0it3r 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
Title: Re: Stop looping when touch is holding
Post by: Jan666 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
Title: Re: Stop looping when touch is holding
Post by: Jan666 on October 12, 2022, 02:53:54 pm
Why is there no Touch examples on the "Events explained" tutorials?
Title: Re: Stop looping when touch is holding
Post by: eXpl0it3r 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
Title: Re: Stop looping when touch is holding
Post by: Jan666 on October 14, 2022, 12:01:25 am
Exist there something like this -> window.setKeyRepeatEnabled(false) for Touch?
Title: Re: Stop looping when touch is holding
Post by: eXpl0it3r on October 14, 2022, 12:37:08 pm
No, there isn't, you'll have to track the current state yourself.