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

Author Topic: smooth timed animation  (Read 1893 times)

0 Members and 1 Guest are viewing this topic.

chris23she

  • Newbie
  • *
  • Posts: 2
    • View Profile
smooth timed animation
« on: December 13, 2018, 08:05:07 pm »
Yes hi all fellow game devs. I have a problem with my the animation part of my code. What happens is the movement is choppy and the animation plays too fast. I know it is because i don't have a fps timer but I'm stuck. I've looked everywhere for help. so here I am. Please any help will do. 




while (window.isOpen()){


        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();

        if((event.type==sf::Event::KeyPressed && event.key.code==sf::Keyboard::Up)){

            //pla.move(0,-2.f);

   rec.left=0;
   if(clock.getElapsedTime().asSeconds()>1.0f){
         if(rec.left==48)
            rec.left=0;
         else
            rec.left+=16;
      //   pla.setTextureRect(rec);

      clock.restart();
      }
pla.setTextureRect(rec);
//rec.left=0;
« Last Edit: December 13, 2018, 08:56:03 pm by chris23she »

barnack

  • Jr. Member
  • **
  • Posts: 56
    • View Profile
Re: smooth timed animation
« Reply #1 on: December 13, 2018, 09:06:40 pm »
well you're not using the timer as you thought i guess.You're using a timer relative to when the clock started, when what you need is the time elapsed since last step of the cycle.
You can either reset the clock at the end of the step or keep a separated delta time variable.

Or to make your life easier, make a fixed duration step game :)

chris23she

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: smooth timed animation
« Reply #2 on: December 13, 2018, 09:36:51 pm »
Ok Barnack could you provide me with an example of using the clock to help with me animation? Thank you.

 

anything