Scrolling Demo

Published November 30, 2006
Advertisement
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:

ScrollingDemo

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

SourceCode

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...
Previous Entry New PC
Next Entry Untitled
0 likes 4 comments

Comments

HopeDagger
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!
November 30, 2006 10:41 AM
Samsonite
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?
November 30, 2006 01:02 PM
Jesse Chounard
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.
November 30, 2006 01:22 PM
Rob Loach
Yay 2D Games!
December 01, 2006 08:06 AM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement

Latest Entries

Goodbye, Gamedev!

1210 views

Untitled

1080 views

Merry Christmas!

1111 views

Untitled

1064 views

Scrolling Demo

1004 views

New PC

883 views

Untitled

826 views

Untitled

857 views

Progress.

885 views
Advertisement