Drawing infinite grid

Started by
11 comments, last by zgintasz 11 years ago
I'm making a 2D map editor and I'm trying to make an infinite(pseudo of course) grid. And then later I need to check in which grid's square is the certain point(mouse pointer). The grid shouldn't stick on the screen like a GUI, user should see grid like so(like "scrolling"):
How can I do that?
P.S. I'm using winforms and opentk if it makes any sense.

Game I'm making - GANGFORT, Google Play, iTunes

Advertisement

Translating the grid by the mouse delta when a mouse button is held would be the simplest solution but what specifically are you having trouble with?

any example? I move my camera when mouse is pressed, so if I move a grid too, grid will be kinda "stick", like a game's hud. But I want to make it like in this video but infinite.

Game I'm making - GANGFORT, Google Play, iTunes

I'm not following what your problem is. Do you have the grid already? If so, you say you move the camera, what is the problem? Translating the camera or grid will achieve the same thing albeit in opposite directions. Or is the problem with rendering the grid?

It's hard to explain for me... Can you give me a code for infinite grid like in that video?

Game I'm making - GANGFORT, Google Play, iTunes

Are you asking how to do it using the tools you use (winforms/opentk?), or are you asking how to structure and code it (store unlimited amount of tiles, load them, show the correct ones at correct offset...)?

o3o

"structure and code it (store unlimited amount of tiles, load them, show the correct ones at correct offset...)"

yes, exactly.

Game I'm making - GANGFORT, Google Play, iTunes

Well, first of all you want to store the tiles in chunks. (lets say 32*32 tiles per chunk)

This way you can render the chunks that are visible, and you can create the chunks as you scroll further. Maybe even save chunks to disk if theres a problem with memory and theyre far away...

As you want infinite terrain, you cant really use a huge grid of those chunks (if you can without using up too much memory, its probably simpler that way. Depends how you define "infinite"). You want a tree like container to store them (quadtree or some kind of hash map container...) so you can store lets say the chunk at 3,6 and the one at 64,12553 and leave the left empty.

Then you need a camera, to represent where on top of the terrain you are looking at. From the position of the camera and the size of the screen, you can find a rectangle. Find the chunks inside the rectangle (convert the corners to chunk-coordinates, like chunk 1,1 or chunk 4,5, then get all the chunks in that rectangle...), then render them with the appropriate offset from the screen center (difference between the chunk position and camera position)

For starters, i would make a single chunk, and a camera, and make the chunk render in the right spot as you move the camera.

o3o

I'm trying to make it almost for a week... If somebody already did it, I would be very thankful if that person would share the code.

Game I'm making - GANGFORT, Google Play, iTunes

What have you tried?

This topic is closed to new replies.

Advertisement