How to Create a Grid for a 2D Game?

Posted by SoulBeaver on Game Development See other posts from Game Development or by SoulBeaver
Published on 2011-02-24T10:17:22Z Indexed on 2011/02/24 15:33 UTC
Read the original article Hit count: 211

Filed under:
|
|
|
|

So I'm currently writing the engine for my videogame. I've almost integrated Tiled (I think) so I should have a map-creator here soon.

My question is, how do I actually make the grid? I'm really confused here. If I create a large map with, say, 20x20 grids the size of 32x32 (screen size 640x640), then what do I do with it?

Let's say I have the code for creating a window, and then place a player sprite that I can move with input, that's fine. If I use one map that's as big as the screen, then every pixel on the map is also a pixel on the game screen. The mapping is exact.

Now what happens if I have a 2000x2000 map, for example? My character would have to keep moving and move the map around (or rather the camera focused on the player moves). Then I can no longer say that the screen maps exactly to the pixel position of the map.

I tried making a Grid class that maps out the screen area to 32x32 tiles, but I'm not sure if that makes any sense. Once the map moves each tile would have to update its information, or something. I'm just really confused here.

How do I actually make the tiles and a grid and map them to the data I get from tiled, or that I make myself? Are there any good examples of source code that I could look at?

© Game Development or respective owner

Related posts about 2d

Related posts about tiles