Hi. I've got a sf::Sprite inheritor and I want to make it perform attack animation. The problem is that the duration of that animation must be much longer than a quick button click.
I made "attack" method as a thread that locks other methods from changing sprite's position and texture.
But that texture doesn't seem to change. When R key is pressed, strikev2() is called.
void Leoric::strikev2()
{
std::thread execute(&Leoric::performAttack, this);
execute.join();
}
void Leoric::performAttack()
{
locked = true;
sf::Clock clock;
auto start = clock.restart().asMilliseconds();
while (clock.getElapsedTime().asMilliseconds() - start < 1000)
{
setTexture(strikeAssets[look][static_cast<int>(clock.getElapsedTime().asMilliseconds() / 250)], true);
std::cout << clock.getElapsedTime().asMilliseconds() / 250 << std::endl;
}
locked = false;
}
So in performAttack I exactly want my texture to change 4 times and it doesn't happen but locked makes the effect and std::cout also prints integers. I think the problem is syncing texture in main. Could you, please, suggest how should I fix that?