[SDL] correct way of map scrolling
NBarnes
nbarnes at gmail.com
Thu Aug 9 13:13:09 PDT 2007
Stefan Hendriks <stefanhen83 at gmail.com> wrote:
> Are you really going to change all positions of your sprite? Instead,
> change the position of your screenport and calculate the X and Y
> positions from there.
>
> ie.
>
> CameraX = 10;
>
> SpriteX = 10;
>
> will result into:
>
> drawX = SpriteX - CameraX;
>
> the same goes for Y. This way you do not have to process your scroll
> logic in your drawin routine (seperate drawing & logic).
>
> Another tip would be to simply do a 'continue' when the sprite is not
> in your viewport, skipping all other code it has to check which is
> irrelevant.
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.
More information about the SDL
mailing list