SFML community forums

Help => Graphics => Topic started by: Sumzary on October 27, 2012, 06:38:42 pm

Title: Moving sf::View smoothly
Post by: Sumzary 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? :)
Title: Re: Moving sf::View smoothly
Post by: 22ndCG 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.
Title: Re: Moving sf::View smoothly
Post by: eXpl0it3r 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 (http://gafferongames.com/game-physics/fix-your-timestep/).
Title: Re: Moving sf::View smoothly
Post by: Sumzary on October 28, 2012, 10:06:59 am
thank you both for the answers.