How do I create an "infinity" map using tilemap

Get help using Construct 2

Post » Thu Oct 08, 2015 4:44 am

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.
viewtopic.php?f=147&t=120451&p=862291&hilit=terrain#p862291
B
92
S
32
G
107
Posts: 5,274
Reputation: 69,959

Post » Thu Oct 08, 2015 1:51 pm

@R0J0hound

I'll try to learn from your example. Thanks :)
B
56
S
21
G
3
Posts: 602
Reputation: 6,612

Post » Fri Oct 09, 2015 7:23 pm

@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...
B
56
S
21
G
3
Posts: 602
Reputation: 6,612

Post » Fri Oct 09, 2015 8:52 pm

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.
B
92
S
32
G
107
Posts: 5,274
Reputation: 69,959

Post » Fri Oct 09, 2015 9:39 pm

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.
B
56
S
21
G
3
Posts: 602
Reputation: 6,612

Post » Fri Oct 09, 2015 10:06 pm

Using a tilemap for this could be tricky and may not give any gains since it looks like you'd have to update the whole tilemap every time you scroll. I'll have to think about it some more though.
Scrolling in other directions will only take one event a piece, and will look much like the one to scroll right. I'm away from my PC atm.

Only the randomize seed action sets the state. The perlin2 expression will always give the same value for an xy if the seed is the same.
B
92
S
32
G
107
Posts: 5,274
Reputation: 69,959

Post » Fri Oct 09, 2015 10:55 pm

R0J0hound wrote:Using a tilemap for this could be tricky and may not give any gains since it looks like you'd have to update the whole tilemap every time you scroll. I'll have to think about it some more though.
Scrolling in other directions will only take one event a piece, and will look much like the one to scroll right. I'm away from my PC atm.

Only the randomize seed action sets the state. The perlin2 expression will always give the same value for an xy if the seed is the same.


I see, so the result would be the same generation but "mirrored".

I wanted to use tilemap because using several objects will harm a lot the game's performance and, for an 8x8 or16x16 tile, which is what i'm focusing, would be unplayable.

I might think another alternative where I don't need to save an infinity world generation and all it's changes made by the player, since that's the whole point of using this plugin. Although wouldn't fit well in a game like Terraria that I'm trying to create.
B
56
S
21
G
3
Posts: 602
Reputation: 6,612

Post » Sat Oct 10, 2015 1:50 am

What could be done is a chunk based approach so the tilemap could be used. The idea would be to do the same as my example but use multiple tilemap objects that you move around and update the tiles in them when they're moved around.
I'll try to give that a go tomorrow, it sounds promising.

The next problem to consider is a way to keep track of terrain changes if you want to be able to add/remove tiles as the game runs.
B
92
S
32
G
107
Posts: 5,274
Reputation: 69,959

Post » Sat Oct 10, 2015 5:32 pm

Ok, here's the result:
https://dl.dropboxusercontent.com/u/542 ... lemap.capx
Probably should have called it spelunking turtle.

I set it up with 64x64 tilemaps with 4x4 tile size and it works decently. I get about 30fps on my machine, so I assume most others will get a higher fps. I briefly tried 128x128 tiles but it seemed to stall a bit more. Also I had some more fun with perlin noise in this one. I found you can combine it in various ways to create some interesting terrain.

It can be made faster I think if I use some javascript to do what the update function does, and create a json that can be loaded into the tilemap. But for now it's decent.
B
92
S
32
G
107
Posts: 5,274
Reputation: 69,959

Post » Sun Oct 11, 2015 3:26 am

@R0J0hound

Pretty nice, I'd never think this way. I was thinking about using just 4 tilemaps, 2 for the X and 2 for the Y.

Here is the beginning. https://www.dropbox.com/s/z5upfgvu6euxc ... .capx?dl=0

I still need to make the tilemaps arrangement for the Y axis, place underground materials, caves and the most difficult, generate enemies and the blocks that were broken and record both. But now I have a good starting point.

You helped a lot, man. Thank you.
B
56
S
21
G
3
Posts: 602
Reputation: 6,612

PreviousNext

Return to How do I....?

Who is online

Users browsing this forum: Fenix18, Lancifer and 52 guests