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

Author Topic: Thor Animations, moving sprite  (Read 4486 times)

0 Members and 1 Guest are viewing this topic.

mguerriero

  • Newbie
  • *
  • Posts: 7
    • View Profile
    • Email
Thor Animations, moving sprite
« on: June 11, 2012, 12:54:54 pm »
Hi, I' m using the animation example in Thor's source code (https://github.com/Bromeon/Thor/blob/master/examples/Animation.cpp) and, when I try to move the sprite, the animation automatically stops!

If I put at line 69 of the example this:
case sf::Keyboard::D:
                animator.playAnimation("drive", true);
                sprite.move(100, 0);
                break;

the sprite is moved but during the transiction the animation is stopped. Can anyone help me having an animated transiction?
« Last Edit: June 11, 2012, 01:25:07 pm by Laurent »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Thor Animations, moving sprite
« Reply #1 on: June 11, 2012, 01:30:13 pm »
Thanks Laurent for the move and the code editing! :D

I'm not quite sure how Thor handles the playAnimation function, but it could be that whenever you call it, the animation starts again from the beginning, thus if you 'start' the animation new everytime you move it, it will always show the first image of the animation i.e. it will look like it's not animated anymore.
You could start the animation when the event KeyPressed is emitted and stop it (or change it to the none moving animation) when the event KeyReleased gets emitted or you could use a boolean to check the state on your own.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

mguerriero

  • Newbie
  • *
  • Posts: 7
    • View Profile
    • Email
Re: Thor Animations, moving sprite
« Reply #2 on: June 11, 2012, 03:44:30 pm »
Oh ok, I solved using a KeyReleased event! Thank you very much :)

mguerriero

  • Newbie
  • *
  • Posts: 7
    • View Profile
    • Email
Re: Thor Animations, moving sprite
« Reply #3 on: June 11, 2012, 04:01:24 pm »
No, wait! It didn't really solve my problem. I do this
bool right = true;
   
    // Clock
    sf::Time time = frameClock.getElapsedTime();
    float elapsed_time = time.asSeconds();
   
    switch (event.type)
        {
                case sf::Event::KeyPressed:
                    if (event.key.code == sf::Keyboard::Right)
                    {      
                if (right)
                {
                    animator.update(frameClock.restart());
                    animator.playAnimation("move_right", true);
                    right = false;
                }
                move(15 * elapsed_time, 0);
                    }
                break;
               
                case sf::Event::KeyReleased:
                    if (event.key.code == sf::Keyboard::Right)
                    {
                right = true;
                    }
                break;
        }
and the animation is stopped when the Sprite starts the transition. animator is a "thor::Animator<sf::Sprite, std::string>"

mguerriero

  • Newbie
  • *
  • Posts: 7
    • View Profile
    • Email
Re: Thor Animations, moving sprite
« Reply #4 on: June 11, 2012, 10:25:55 pm »
I fixed adding a "animator.stopAnimation ();" in each KeyReleased events