[SDL] correct way of map scrolling

Will Langford unfies at gmail.com
Thu Aug 9 13:34:59 PDT 2007


>
> This is pretty much exactly how I've handled these issues in the past.
>
> The other thing I've done is, in a tile-based system, instead of
> keeping around one huge Surface with the entire map laid out on it,
> just parsed the camera into seeing what tiles are visible and blitting
> them to the viewport with appropriate offsets for their map location
> and the camera position.
>
> But it looks like you're using a full pre-rendered map instead of
> something generated more dynamically, so that wouldn't work as well
> for you.
> _______________________________________________
>

In a previous thread I mentioned a tiler I've written in Allegro and SDL.
It kept a background that was 5 tiles bigger than the screen/viewport on
each side and would scroll around that, recreating/recentering the tiled
world whenever the viewport went beyond the background of size of the
pre-done background.

There's a concern with this -- recreating the background every so often
might cause a slight delay compared to regular scrolling.  Uneven CPU spikes
while recreating the background, that is.  Back when I wrote the tiler, I
didn't have this speed issue... but back then the main concern was memory
usage rather than processor usage.

If you're doing a true tiling system (say, 32x32 tiles or similar), then ya
might consider just recreating the background every frame.  You'll
undoubtedly be animating EVERY tile, so you'll have to redraw it anyway...

-Will
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20070809/3a9f2eb5/attachment.html 


More information about the SDL mailing list