Re: Problem gettting a smooth continous background scroll (SDL2)
Jonathan Dearborn <[email protected]>
| Newsgroups | gmane.comp.lib.sdl |
|---|---|
| Message-ID | <CA+DSiHa=OV0pn-SKqCJe-XyW9oYo0Jp0b+v5iXEJRiSNsW2h_g@mail.gmail.com> |
I wanted to point out something about smooth scrolling (though this is not your particular problem), that SDL uses integer positions and so doesn't support subpixel positioning. If you have a low rate of scrolling, like on the order of 10 pixels per second or less, you will experience pixel-sized jitter. Jonny D On Wed, Aug 17, 2016 at 1:44 PM, BenoitRen <[email protected]> wrote: > 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 > > _______________________________________________ SDL mailing list [email protected] http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org