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

0 favourites
  • 4 posts
From the Asset Store
This pack has plenty of options to help your game background & ambience sound come to life.
  • 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 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.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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)

  • 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.

  • Thanks for the replies.

    : 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.

    : 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:

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

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