Jump to content
  • Advertisement
Sign in to follow this  
zgintasz

Drawing infinite grid

This topic is 2027 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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?

Edited by GeneralQuery

Share this post


Link to post
Share on other sites

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

Edited by zgintasz

Share this post


Link to post
Share on other sites

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...)?

Share this post


Link to post
Share on other sites

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

yes, exactly.

Edited by zgintasz

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!