SFML community forums

Help => General => Topic started by: dramcryx on February 04, 2019, 06:01:04 pm

Title: Threaading a sprite
Post by: dramcryx on February 04, 2019, 06:01:04 pm
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.
(click to show/hide)
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?
Title: Re: Threaading a sprite
Post by: eXpl0it3r on February 04, 2019, 08:32:02 pm
Threads are definitely not the answer here. Instead you can take a clock and track the passed time and base your animation on that.
Title: Re: Threaading a sprite
Post by: dramcryx on February 12, 2019, 10:50:02 am
I thought I deleted this post because I fugired out the problem quickly.
The problem was using join() instead of detach().
Second one worked out well.