Hello!
from the beginning i used only if loops and i encountered some problems. I switch to use Event instead. But i feel like the events have some delay(probably bad coding xD). I need someone who can tell what the problem is and how I can make it better without the delay on events
. When i click with the event code it is delay or I need to spam click for the action to happen.
if code =
sf::Vector2i mousepos = sf::Mouse::getPosition(*window);
if (IsThisStrenght = true && mousepos.x > this->getPosition().x && mousepos.x < this->getPosition().x + this->getGlobalBounds().width && mousepos.y > this->getPosition().y && mousepos.y < this->getPosition().y + this->getGlobalBounds().height)
{
if (sf::Mouse::isButtonPressed(sf::Mouse::Left))
{
if (this->score->reps >= 10)
{
this->stats->Strength += 1;
this->score->reps -= 10;
}
}
}
event code-
sf::Vector2i mousepos = sf::Mouse::getPosition(*window);
sf::Event event;
while (window->pollEvent(event))
{
if (IsThisStrenght = true && mousepos.x > this->getPosition().x && mousepos.x < this->getPosition().x + this->getGlobalBounds().width && mousepos.y > this->getPosition().y && mousepos.y < this->getPosition().y + this->getGlobalBounds().height)
{
if (event.type == sf::Event::MouseButtonPressed)
{
if (event.mouseButton.button == sf::Mouse::Left)
{
if (this->score->reps >= 10)
{
this->stats->Strength += 1;
this->score->reps -= 10;
}
}
}
}
}
grateful for answer