How do I generate things on the fly/stream my layout?

Get help using Construct 2

Post » Wed Mar 18, 2015 11:19 am

So for the past few days I've been having fun making a basic procedural map generator for a 2d sidescroller (kinda like terraria),
here is what I got so far https://dl.dropboxusercontent.com/u/55828593/RandomMap/index.html might take a while to load, press F5 to get a different result.

Basically, it's a 2D array used as a "tilemap".
I set up my array values with different stuff then create sprites for Each array XY at (Array.CurX,Array.CurY) depending on the array value at those points.

But when I try to expand the Array width too much (cause I want a big level/open world), the game will crash and won't even load.
Probably cause too many sprite/objects are created (If I remove the process of spawning the sprites the game will load fine, so it can generate the array but not create that many sprites).

So I'm trying to find a way to "spawn" things on the fly.
I've thought about spliting my layout into different zones on the X axis.

For example if player is in zone 4, it will only spawn the sprites for the zone 3, 4 and 5. If player go to zone 5, it will spawn the sprites into zone 6 and destroy the sprites into zone 3.
When a player is in x zone, only sprites in x-1, x and x+1 zones will be created. You get the idea?

I'm not even sure if it can spawn that many sprites fast enough without getting some lag but it might work (if I make the zones small enough maybe).

The thing is I have no idea how I could do that, I was thinking of another array to make the zones but I'm not sure how to implement it.
That's why I'm asking you for help.
Last edited by balsh on Thu Mar 19, 2015 6:37 am, edited 2 times in total.
B
9
S
4
G
1
Posts: 31
Reputation: 1,384

Post » Wed Mar 18, 2015 3:11 pm

use invisible objects as triggers... on collission with player, make that object spawn your enemies a given coordinates, and then you can deactivate the trigger with a variable or just destroying it to spawn just once... or leave or leave it there so enemies will respawn if you go back to that area (like first megaman games)
Image
B
57
S
13
G
6
Posts: 271
Reputation: 12,073

Post » Thu Mar 19, 2015 6:45 am

You might take the minecraft route and use chunks. You can put Arrays in Containers with tilemaps, then when the player gets too far away, Serialize it as a JSON and put it into webstorage or whatever, then destroy it. The only problem is I think C2 puts an upper limit on how big a layout can be.
B
14
S
5
G
1
Posts: 189
Reputation: 1,536

Post » Thu Mar 19, 2015 8:57 pm

Thanks for the replies.
@Danutos: I've been thinking of using those invisible triggers but I'd have to set them up manualy I guess and then set the different conditions for all of them which can be a real pain cause I want the map to be quite big. I need a somewhat more automated process.


@bladepenguin: The thing is I'm not using a noise (so no seed) for my array, just random numbers from construct and if I split it or remove it on the fly they'll be different every time I wnt to recreate them.
The layout limit is not a problem for now, I just want to make it big enough not especially infinite(Terraria maps are not infinite as well, just quite big).

So the part I need to tweak in my project is here:

Image

(spirtes are 8x8 pixels)
I'm trying at the moment to spawn the sprites when the map.curX*8 is close to the viewport
I've found a way to destroy the sprites when they're outside the viewport+n value, with the Pick by evaluate expression. But I still need to find how to create them only somewhere around the viewport (line by line when player moves) and make this happen only once so that it doesn't create sprites instances where there are already some (no overlap).
B
9
S
4
G
1
Posts: 31
Reputation: 1,384


Return to How do I....?

Who is online

Users browsing this forum: Ajbael, kiko2015, lukezero, RoaringPixels and 11 guests