How do I create an "infinity" map using tilemap

0 favourites
From the Asset Store
Fully commented source code/event sheet & sprites to create a space shooter game
  • I have created a basic map generation. Basically this system randomly creates all the terrain, but i dont want a fixed layout where you can reach the start and the end of the map, I want to create something like a sandbox game. In order to do that, instead of my character moving, all the rest of the map needs to move to the appositive direction, so if I jump, the character don't move but the rest on the screen will move down. If I walk to the right, the map will move to the left and so on. The problem is that i don't know how to do that with tilemap because I can't just work with it's width and height like a tiled background would work.

    Also, I'm using array to make it possible. I thought about having an extremely big array and start feeding it in the middle of it's width and height and then make this transition about what is shown in the tilemap and what is deleted as it goes away from my view.

    Obs: the array should be, in any situation, extremely big in order to feel like a sandbox so the player couldn't reach the start or the end of the map, so it would feel like an infinity map.

    To sum up, how do I create an "infinity" map using tilemap and array?

    Edit: Which's the limit of width and height of an array? How much megabytes would have my savegame if this array had 100k of width and height filed?

  • Javascript's numbers are stored in 8 bytes of memory. Assuming your array is filled with 100 000^2 of these numbers, it would consume roughly 80 000 000 000 bytes of memory / disk space. In terms of megabytes that would be 76 294, which is far too much for anything practicable.

    For large scale "infinity"-like map, it's much better to work with "procedural generation" and only save alterations to the map (if any).

  • Javascript's numbers are stored in 8 bytes of memory. Assuming your array is filled with 100 000^2 of these numbers, it would consume roughly 80 000 000 000 bytes of memory / disk space. In terms of megabytes that would be 76 294, which is far too much for anything practicable.

    For large scale "infinity"-like map, it's much better to work with "procedural generation" and only save alterations to the map (if any).

    You mean to don't keep stored what was already created? If so how can I generate what was discovered by the player before?

  • Magistross

    I was looking at it and I found a method using seeds, where you randomly generates this seeds (a sequence of letters) and then this seed will generate the map. It means that this seed can be saved to generate the same map over and over. It's awesome because u just need to save the "trigger" that created that kind of world and not actually the whole world. But then it starts to be really complicated and I don't see right now how to use this method with arrays and tilemaps in construct 2.

  • It's in fact quite a complicated subject. But you got the basics right, it all boils down to using seeds so you can manipulate the RNG in producing consistent and predictable results.

  • Magistross

    Well, I'll try translate this method in construct 2. I can see that it will be a really tough task but I'll try.

  • You could also settle for a hybrid method. Procedurally generate chunks of new terrain on demand, and only have the current chunk and its neighbors loaded in memory at a time. This way, generation would only occur once per chunk, and the world would still be consistent and "infinite" without weighting terabytes of data.

  • Magistross

    Actually I was thinking about something like this.

    Each letter would represent a previously created small pattern. But if, in this randomization of seeds, happens to occur two same letters in sequence, it would represent a bigger pattern, like an evolution of the small pattern represented by the letter A.

    Would be really painful to create all these patterns before start randomizing anything, but after that the possibilities is huge.

    Also I'm only thinking about the simple part of the terrain( the "silhouete" - It's a platform game). I didn't think about other elements on the map yet.

    The idea behind of all of this is that I'm trying to create a game where you can go from planet to planet and find different terrains, materials and animals/enemies each time you explore a different planet.

  • I'd recommend using the noise plugin:

    It lets you use perlin noise which is the basis of Minecraft's terrain generation.

  • I'd recommend using the noise plugin:

    It lets you use perlin noise which is the basis of Minecraft's terrain generation.

    I did some research about this perlin noise. Could you please sum up the subject for me? All the video tutorials about this method is in english and my spoken/listen english isn't that good to understand such a complicated theme. Also, I'll look at it for sure but this plugin is for it or just can be used for this?

    Thanks

    Edit: I'm looking at it and I don't see how it could be helpful to create random terrain in a platform game using tilemap/array. I can see that the different shades is used to represent something else, but I'm not getting how to use this plugin and this "clouds" and translate to my tilemap which is dependent on what tile was placed before because they have a sequence (e.g after tile 2 I can place tile 3 on the same Y or 4 with Y-1 regarding to the last tile position)

  • With that plugin you set a seed then use the perlin2d(X,y) to get a value from -1 to 1 for any position. So yes, it's like a cloud.

    For terrain the usual method is to use a threshold on the result. Like if the value is greater than 0 make a tile, else leave that spot empty.

    The only gotcha of the plugin is if x or y are integers (no decimal part) the result of the perlin expression is 0 so you usually should multiply X and y by some decimal number before using it as a parameter. Also you'll be doing that anyway to scale the noise to your preference.

    That said, it's just and idea and may not work well enough in some cases.

    Edit:

    Here's an example of getting 2d terrain with that plugin.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • R0J0hound

    I'll try to learn from your example. Thanks

  • R0J0hound

    Could you explain me this formula?

    if (3+rnd1*1)*sin((1.5+rnd2)*360*Array.CurX/40+rnd3*45)+15 < Array.CurY

    Are all the values arbitrary? Why greater than CurY? Also, I don't see you using Seed here. I'm struggling with this plugin and with all your formulas to make things work.

    I'm attempting to give up because my math skill isn't great.

    My idea for the game is to create a sandbox world. To do that in C2 I need to move everything, instead of moving the player right? So if the player "move" to the Right, the world have to move to the left, eventually the first column of the array will be deleted to give space to the last column on the right to update the map. The same if I'm going down. The perlin noise and all your examples allow me to do that, right? If so, could you explain me a bit about the formulas and what they represent? I'm really lost right now, specially with these arbitrary values.

    Edit: Also it seems that these formulas rely on the CurX and Y. In my limited understanding, it seems that it wont generate new terrain but repeating the same as the last pattern created in that same X and Y because all the values are the same in this case - rnd variables, the axis...

  • That particular formula doesn't use perlin noise, it's just a sine wave.

    Most of the values are pretty arbitrary, but the general form of the equation is:

    https://www.google.com/webhp?sourceid=c ... 0of%20sine

    y = amplitude * sin(frequency*x + phase)

    amplitude is how high the waves go.

    frequency is how close the peaks are.

    phase is the initial x offset.

    In the formula as I wrote it in the capx.

    rnd1, rnd2, rnd3... are just some random numbers I saved. And the Array.curX/40 basically scales it to the array which is 40x30. The other numbers just tweak it a bit.

    I used grater than because i wanted to fill in everything below that graph.

    As far as an example here's how I would do infinite terrain with perlin noise.

    https://dl.dropboxusercontent.com/u/542 ... croll.capx

    It matches the "perlin noise with vertical gradient" in that previous capx.

    The scrolling is done by covering the screen with the blocks, and disabling/making invisible the blocks that should be clear. Then as the blocks go off the left of the screen they're moved to the right and updated.

    The shape of the terrain is defined in the update function. Just by fiddling with the numbers you can get a wide variety of terrain shapes.

  • Thanks for your time, R0J0hound

    I'm playing with the formula and I'll try to adapt your example using tilemap instead of objects, as scrolling both sides/top/down. Btw, your example is absurdly powerful already.

    One curiosity about this plugin: noisejs.perlin2 expression is setting the new state of the object by itself? Because it's just a compare value condition which doesn't pick any object and there are no other event updating block's Y.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)