2
\$\begingroup\$

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?

\$\endgroup\$

2 Answers 2

4
\$\begingroup\$

I found this very helpful: http://www.sdltutorials.com/sdl-maps/

\$\endgroup\$
2
\$\begingroup\$

I'm not sure what language you're doing this in but this is how I generally do it in XNA:

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.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .