Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Threaading a sprite  (Read 1675 times)

0 Members and 1 Guest are viewing this topic.

dramcryx

  • Newbie
  • *
  • Posts: 7
    • View Profile
    • Email
Threaading a sprite
« 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?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: Threaading a sprite
« Reply #1 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.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

dramcryx

  • Newbie
  • *
  • Posts: 7
    • View Profile
    • Email
Re: Threaading a sprite
« Reply #2 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.

 

anything