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

Author Topic: Moving sf::View smoothly  (Read 1612 times)

0 Members and 1 Guest are viewing this topic.

Sumzary

  • Guest
Moving sf::View smoothly
« on: October 27, 2012, 06:38:42 pm »
I am trying to make very smooth view movement, like in Super Meat Boy and such.

Currently, I am using this line of code to achieve this:

viewRect.Offset(((playerPos.x - lastPlayerPos) / viewSpeed) * timeDelta * 20.f,
                ((playerPos.y - lastPlayerPos) / viewSpeed) * timeDelta * 20.f);

If there is an fps lag spike however, the timeDelta variable will get bigger and the view will be shot forward with great speed. How could I improve this? :)
« Last Edit: October 27, 2012, 06:47:08 pm by Sumzary »

22ndCG

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: Moving sf::View smoothly
« Reply #1 on: October 27, 2012, 07:10:44 pm »
You could simply "slow down" the entire frame (physics, ai, rendering, everything) to accommodate for lag. That way the game will only slow down when there is lag, but not be jerky. I wouldn't be terribly concerned with it, however, as no one really expects a game to look great when its lagging.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: Moving sf::View smoothly
« Reply #2 on: October 27, 2012, 07:44:01 pm »
You could work with a fixed timestep instead or take the average deltatime (i.e. time over x frames or frames over x seconds).
You might want to read this blog post.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Sumzary

  • Guest
Re: Moving sf::View smoothly
« Reply #3 on: October 28, 2012, 10:06:59 am »
thank you both for the answers.