2D Screen Scrolling

Previous topic - Next topic

david

Hi, I am currently making a 2d game and was wondering how you make the screen scroll? I mean like your character stays in the same place, but the background scrolls around where you are moving. Like in the sample game, mario, the background moves. How do you do that?

Thanks,

David

Ian Price

For the most efficient method of scrolling a background stage, then you're going to have to look into tiles and tile engines. These are useful for all games, not just for scrolling games.

Tiles are individual blocks of images (like pieces of a jigsaw puzzle) that when placed together form an image. You'll then need an engine to place all of your tiles into a specific order and scroll as necessary.

Tile engines are actually very easy to create, although for someone who's never used one, then they can be quite challenging.

There are various tile engines that you can borrow from other languages and adapt to your own needs, but again this requires some knowledge of exactly how they work.

A good freeware map editor (this allows you to load in your own tiles and then place them into your level is Mappy) and as luck would have it, Moru has created a Mappy loader for GLBasic that should allow you to import any maps into your game, ready for use - http://www.glbasic.com/forum/viewtopic.php?id=1633
I came. I saw. I played.

PeeJay

Good advice there from Ian

The only thing I can offer it a more general look at how it works.

Normally you would have a character moving around a screen, with co-ordinates stored in x and y.

If we want the background to move instead, we lock the player in position, and move the background by -x and -y. In other words, the background moves in the opposite direction to your player (since your player position is now fixed)

Good luck, and don't be afraid to ask questions ;)
www.peejays-remakes.co.uk
For games, remakes, and GL Basic Tutorials
Artificial Intelligence is no match for Natural Stupidity