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

Author Topic: have fast moving sprites without distortion?  (Read 3320 times)

0 Members and 1 Guest are viewing this topic.

sontung

  • Newbie
  • *
  • Posts: 1
    • View Profile
have fast moving sprites without distortion?
« on: July 27, 2017, 03:05:31 pm »
Hello everyone.

I am new with SFML and I'm having problems moving fast sprites across the screen.

For some reason when I try to accelerate the sprite it begin to truncate and flicking. If I reduce the speed, everything goes smoothly.

Another strange effect that I'm getting is that during the course of the sprite it seems to do some "bumps" by changing the speed at regular intervals.

To move the sprite I'm using:
position x + = speed * elapsed time

I need to learn about best practices and how to have extremely fast moving sprites around the screen without distortion.

Does anyone have any tips or suggestions?

Thanks!

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: have fast moving sprites without distortion?
« Reply #1 on: July 27, 2017, 03:12:57 pm »
Just to get an estimate, what's "extremely fast"?

To due away with most "artifacts" you have to understand that your screen has only a fixed amount of pixels, so whenever you use a floating point position, OpenGL will have to estimate how to map the texture pixel to the screen pixel. Which can lead to issues where not the expected pixel gets used due to rounding up or down one pixel.
So to control the proper positioning, you can do the rounding yourself and match the pixels perfectly.

As for smooth movement you need to know that the frame time is not a fixed value. It varies slightly for every frame. As such the elapsed time isn't constant and thus your movement won't be constant.
For a "proper" physics calculation you should Fix Your Timestep.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Ricky

  • Jr. Member
  • **
  • Posts: 99
    • View Profile
    • Tejada
    • Email
Re: have fast moving sprites without distortion?
« Reply #2 on: July 27, 2017, 09:51:26 pm »
Can I toot my own horn for a second?

https://ricanteja.github.io/tutorials/2017/07/07/sfgd_1.html

I had the same problem as you and it took me a while to figure out what was going on. You may be using some sort of forced frame limit but I'd recommend against it. Feel free to check out my article on it and give feed back. Hope it helps.
Wilt thou yet say before him that slayeth thee, I am God? but thou shalt be a man, and no God, in the hand of him that slayeth thee.

JayhawkZombie

  • Jr. Member
  • **
  • Posts: 76
    • View Profile
Re: have fast moving sprites without distortion?
« Reply #3 on: July 27, 2017, 10:12:05 pm »
If I may also chime in.

Try using interpolation when rendering.  If you have a fast moving object, it can appear to "jump" between positions, especially when limiting the framerate.

The rendering will not be entirely accurate (at most one frame behind), but the movement will appear much smoother.

Here's a good example of an implementation (but by no means the only one): http://kirbysayshi.com/2013/09/24/interpolated-physics-rendering.html