my game's idea is to use a open world map consisting of say 4096x4096 size, and multiple grids of 64x64 size. When I click on any grid, the map zooms in to show that grid(either creating in from scratch or loading off a JSON) because saving all the grids could not be memory efficient. Is there any algorithm to do like this?
\$\begingroup\$
\$\endgroup\$
1
-
\$\begingroup\$ What did you mean by "saving all the grids could not be memory efficient"? If they're loaded from file, they're already saved. Did you mean that storing all the grids in memory wouldn't be efficient? \$\endgroup\$Pikalek– Pikalek2019-10-10 16:24:30 +00:00Commented Oct 10, 2019 at 16:24
Add a comment
|
1 Answer
\$\begingroup\$
\$\endgroup\$
2
You don't really need any specific algorithm to accomplish this. One way you can achieve that is this:
- Make an array that holds your tiles, most likely a 2D array will do.
- For each tile, make a
jsonfile, that describes what that tile looks like. Name thejsonfiles in a sequence, so the first tile would betile_0.jsonthe next onetile_1.jsonetc etc. - When the user clicks on a tile, depending on which tile it was, open the right
jsonfile, and load everything that it needs.
Depending on what language / platform / tools you are using, this might look different in actual code.
-
\$\begingroup\$ But how do i generate the json file? Like filling the contents of the submaps ? \$\endgroup\$Avra Neel– Avra Neel2019-10-10 15:18:07 +00:00Commented Oct 10, 2019 at 15:18
-
\$\begingroup\$ @AvraNeel That's up to you. Are you using a tool that can export to
json? Or do you want to do it manually?jsonis a very flexible format. \$\endgroup\$Tom Tsagkatos– Tom Tsagkatos2019-10-10 15:24:03 +00:00Commented Oct 10, 2019 at 15:24