Re: Problem gettting a smooth continous background scroll (SDL2)

"BenoitRen" <[email protected]>
Newsgroups gmane.comp.lib.sdl
Message-ID <[email protected]>
I see several problems:

-The duration of one frame when rendering at 60 frames per second is not 16 milliseconds, but 16.67 milliseconds (1000 / 60 = 16.67). This difference in timing adds up.

-Every frame you insert a waiting period of 16 milliseconds. This does not take into account the time it takes to process one frame between the delays.

-SDL_Delay is not very reliable. The operating system's scheduler might decide to allocate some time to another process instead of yours at the time you expect control back.

There are two approaches you can take.

One approach is using timers, which Lazy Foo' also explains in one of his tutorials. To solve the problem of one second not cleanly being divisible by 60, you can combine it with the approach explained by Aaron at Wolfire (http://forums.wolfire.com/viewtopic.php?f=1&t=16539). In short, it makes every first and second frame take 17 milliseconds, and every third frame 16 milliseconds. Personally, I combined all of that with what Disch explained at NESDev (http://forums.nesdev.com/viewtopic.php?f=3&t=6107) to try to mitigate SDL_Delay's unreliability.

The second approach is to have your program wait for vsync after rendering a frame. To use this, pass the SDL_RENDERER_PRESENTVSYNC flag to SDL_CreateRenderer's flags parameter.

_______________________________________________
SDL mailing list
[email protected]
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.