Best way to load stored levels into blank tilemap?

0 favourites
  • 7 posts
From the Asset Store
Best car suspension with spring effect and very cool terrain generation.
  • I'm making a simple quick-fire golf game using tilemaps as the levels.

    Right now I only have one stage for testing, but ideally I'd like to have a bunch of levels stored somewhere, and when a stage is complete, it randomly loads a new level into the tilemap and resets the ball.

    I have no idea how to achieve this though, I tried searching the forums and found similar questions but no real answers that seemed to work for me. I did download a program called Tiled to make levels in but can't seem to get them to load.

    Any help or examples would be appreciated, thanks!

    Tagged:

  • Paint the level in the tilemap in Construct then load your game and trigger the tilemap Download action during the game to save a json file. You can then store the json string from the file somewhere in your game like in a variable or array and use the Load action to load it later. The downloaded json string contains all the data for the level you drew with the positions and type.

    I think you could also set a string variable to tilemap.tilesjson on start of layout which is the same data as above and then pick it out in debug preview, you can click on the variable value field and copy that data to save it for later.

  • I don't suppose you could whip up a quick example of what you're describing? I managed to get it to save the Tilemap.json but not sure what to do with it from here.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Open that file in notepad and the string inside is the data for the tilemap. So you could have an event on start of layout > Load and then for the value use that string.

    That's the simplest form to know how to load the tilemap data. To pick a random level you would need to build that mechanic, you could store the strings in an array and pick a random row. If I get time I can build something but it's late now.

  • Alright I think I may have it working by following your advice, and I also found this tutorial here:

    construct.net/en/tutorials/load-fill-array-json-file-2515

    Still not quite sure on how to select a random tileset yet though but I'll have a play. If you want to make an example at some point though I'd definitely appreciate it!

  • Here you go:

    dropbox.com/s/z89snbjmw8gtfv2/LoadRandomTilemapData.c3p

    You need to create a separate project (Level Builder) where you keep the original tilemaps. Use "Tilemap Download" action to download a json string for each tilemap.

    In your main game create an array with all those json strings. When a new level starts, pick one string at random and load it into the tilemap.

  • Thanks a lot!

    I think with all the information here I've managed to bodge together a solution which works pretty well. Now I just need to make a bunch of levels to test it with!

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