views:

57

answers:

3

Hi, hope not to be .. boring. In my video game development (2d, in Sdl.NET), i would like to create some 2d "map" (top-down map, also called flybird i suppose). I would like to create Big Map, for example 4000x4000 px. Obviously, i would like to show only what the user resolution can be. If my user uses 800x600, i must show a "crop" of my big map.

What's the best approach to solve the problem of the screen scrolling ? And, how to show only the correct "piece" of my map (terrain) ?

+2  A: 

In regular GUI development the approach is to use a ViewPort. Not sure about your platform specifics, but a ViewPort takes care of what the user can see while keeping track of where in the larger "Big Map" the ViewPort fits. In regular GUI programming, you have scrollbars to move around, but you will likely need to manage moving that yourself.

The basic premise of the ViewPort is that the document is much larger than what the user can see. I'm guessing that Sdl.NET doesn't have such a construct per se. (I couldn't find the API docs). You can create one yourself, that will take care of blitting the right portion of the background or Big Map to the screen itself. The ViewPort would just be a couple of points to keep track of the upper left corner of the screen and lower right corner of the screen. Give yourself a couple methods to move the ViewPort and make sure it is within the boundaries of the Big Map.

After that it's just a matter of tying it all together.

It's not uncommon to have a tree of all objects in the scene, so that you can make sure you are displaying just the objects that are supposed to be in the screen. That will help your "Draw" function to blit the background, and any foreground elements inside the view port automatically.

Berin Loritsch
+1  A: 

This sounds like a good opportunity to use a quad-map. This would allow you to "chop" the big map and load "pieces" on-the-fly

S.C. Madsen
+1  A: 

I just googled a bit and found this, which may be what you want: http://cone3d.gamedev.net/cgi-bin/index.pl?page=tutorials/gfxsdl/tut6

Look for the DrawImg and DrawScroll functions.

Zecc