# How to Create a Grid for a 2D Game?

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?

When your character has moved around and you want to move the camera then you change a Vector2 called something like _screenPos or something, which is a variable holding the current position of the screen.
Then, whenever you want to check like a mouse click on a tile or whatever it is you want it to check pixels for then you would add _screenPos to your current mouse position to get the absolute position over the tiles and find which tile you're clicking in the grid.