SFML community forums
Help => General => Topic started by: antton on December 18, 2016, 05:01:24 pm
-
Hello guys!
have received a obstacle when I have worked with my game. When i have over 10 reps I can buy a item and it will cost me 10 reps. The problem is when if i get over 20 reps and buy the item it will take away 20 reps but actually it should only cost 10?!.
this is the code Underneath
if (sf::Mouse::isButtonPressed(sf::Mouse::Left))
{
if (this->score->reps >= 10)
{
this->stats->Strength += 1;
this->score->reps -= 10;
}
}
Pleas someone can help me with this question!
-
sf::Mouse::isButtonPressed is true as long as you press the button. So even if i only lasts a few milliseconds, it's enough to trigger your condition several times.
You should use the MouseButtonPressed event instead.