I want the texture to change to a muted speaker when the player click on the speaker, and after one more click I want the texture to change to the speaker that is on, my problem is that since im doing this in update and since that im also using isButtonPressed the texture is changing instantly every frame, so when i click really fast, it works good, but when i click normally the texture is instantly looping, like changing every frame, so quick. I want to do a normal switch that mutes the audio on click, and when audio is muted, after another click, i want the texture to change to normal again and play the music, i know how to mess with sound and animations but i dont know how to make this simple input thing.
So how to make a simple one input, like:
One click, change the frame but only once.
Another click, change the frame again.
Since my main lang isnt eng and my speaking skills arent as good as i want, i just recorded this vid of the problem:
https://www.youtube.com/watch?v=i7CqAe4QJ2Q&feature=youtu.bethe code:
//speaker
if (engine.checkMouseCollision(*pointer_window, speaker_sprite.getGlobalBounds()) == true) {
if (sf::Mouse::isButtonPressed(sf::Mouse::Button::Left) && isSpeakerMuted == false) {
speaker_sprite.setTextureRect({ 60, 3, 47, 44 });
isSpeakerMuted = true;
}
else if (sf::Mouse::isButtonPressed(sf::Mouse::Button::Left) && isSpeakerMuted == true) {
speaker_sprite.setTextureRect({ 3, 3, 46, 44 });
isSpeakerMuted = false;
}
speaker_sprite.setColor(sf::Color::Magenta);
}
else {
speaker_sprite.setColor(sf::Color::White);
}
}