How do I use arrays to build a level?

0 favourites
  • 4 posts
From the Asset Store
Create your own beautiful snowman in this fun game!
  • Hello all,

    I'm currently working on a game where I am trying to load level data from an array in a way a bit like a tile-map. When loading, however, using the built-in "for each ... element" feature, I can't seem to get anything to be placed correctly. I've attached a file that shows my problem, so if you want to, you can check out the code. Any help would be appreciated!

    Thanks,

    -EmCannon

  • I don't see an attached file.

    Which part are you having trouble with? Loading the data? Or placing the objects in your level correctly based on the array data?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Sorry, I forgot to attach the file. Here it is.

    And I'm having trouble placing the objects in the level based on the array's data.

    drive.google.com/open

  • This is not how you load data from json file into the array..

    You need to change your code like this:

    Note, that "For each element" loop is a sub-event under "On start of layout".

    Also, you have a very inefficient way of storing level objects in the array. You are basically designing the level in the array with numbers. Why not draw it on the TileMap in layout editor? It will be much easier.

    The traditional method is to store object types and their coordinates, something like this:

    wall, 100, 50
    wall, 120, 50
    wall, 150, 50
    chest, 200, 100
    zombie, 300, 120
    

    Of course, you don't enter these numbers manually, you prepare them using some kind of level editor.

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