Jump to content
Sign in to follow this  
  • entries
  • comments
  • views

Scrolling Demo

Sign in to follow this  


I have a little demo here, it's the best I could do in ~1 hour(I consider that quite good given my nature to abandon my simple projects) [smile]

Here is the .exe:


And here is the code for those who wish to take a look:


Basicaly, the program just scrolls a hardcoded map. You use the arrow keys to move.

I just wondered how to do scrolling so I sat down and made this. It's fairly simple but I really hope the code works on bigger games...

Thanks for testing it out!

On another note. I went to Opera yesterday to get a job for our work week next week. They didn't have the time to train me up, but they told me to apply for an internship next summer.
I'm also applying for a C++ Game Programmer at 0ad, which looks marvelous and also has a very interesting setting(atleast for me).

EDIT:I also ought to get one of those christmas avatars...
Sign in to follow this  


Recommended Comments

Some issues with your scrolling system, IMHO:

  • Storing every tile as an object instance might be a little overkill, depending on how much unique information each tile has (if any). You'd save a lot more space, and have an easier time managing a 2D array of, say, integers. Each integer would represent a tile type instead.
  • Storing map tiles as objects is a little, well, odd. ;) You're also wasting a ton of processor power by implementing scrolling as shifting every single tile object in the given scrolling direction when the user scrolls. Rather than moving the whole world to scroll, move the camera instead. :)
  • Drawing every single tile on every single layer per frame is really inefficient, and will definitely add up and be a performance hit. Make sure you only render what the user can see.

Since this is your first whack at scrolling, it's nothing to worry about, but there's many nicer routes you can (and should) take to handling a scrolling 2D tile map. I'm positive that there's plenty of good articles on the matter lingering all over the 'net, that I recommend taking a browse over.

Good luck!

Share this comment

Link to comment
Thanks for testing it out!

But how would you move the camera? I mean. I have no camera class and I cannot figure out how it should be. Could someone help me?

Share this comment

Link to comment
What he means by camera is just the offset you're looking at.

So, instead of shifting everything when the user presses and arrow key, just keep x and y coordinates and modify those. Then, when it's time to render, just draw what you would see on the screen if you map the top left of your screen to the (x, y) offset in your map.

Does that make sense?

And to help with that, have a look at this. (It's off the top of my head, so it might not compile, but I believe the idea is sound.)

startX = TILE_WIDTH / x; // the first tile to be drawn
startY = TILE_HEIGHT / y;
offsetX = TILE_WIDTH % x; // how much we are offset into the first tile
offsetY = TILE_HEIGHT % y;

for(int y = 0; y < SCREEN_HEIGHT / TILE_HEIGHT + 1; ++y)
for(int x = 0; x < SCREEN_WIDTH / SCREEN_HEIGHT + 1; ++x)
RenderTile(x + startX, y + startY, x * TILE_WIDTH - offsetX, y * TILE_HEIGHT - offsetY);

void RenderTile(int tileX, int tileY, int x, int y)
Draw(m_ScreenLayer0[tileY * MAP_WIDTH + tileX], x, y);

If I've only helped to make things more confusing, you should have a look in the "tile-based games" section of the resources here at GameDev. I learned alot from the articles in there, back when I first started.

Share this comment

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!