How do I use an array to give Tiled Objects numbers.

  • I have the basic knowledge of how arrays work, how you can set info and then call it when needed. Almost like a spreadsheet. I am wanting to know how to connect tiles to an array. I have square tiles that are placed near each other to make it look like a normal square grid. I would like to associate a/an (3d) array to the tiles so the array can tell the game what frame to display and what object is on the tile so it can decide if the area of the tile is taken. I'm not asking to use an array to make a grid, I just need to know how to implement an array so that each tile can have a few numbers attached to it.

    I am wanting to do this so when the game is saved it only has to save an array along with a few global variables.

    I may be completely wrong on what I am asking so advice would work as well.

    The grid will be used to project onto an isometric grid. I already know how to do this for the most part. I am only having trouble with the array.

    I guess I may be thinking of Cell Size if that can be implemented somehow.

    ***********

    Also would it be possible to add a row and column to an array on all four sides at once during game-play without messing up the layout of objects on the grid? As in having the level grow when certain goals are achieved, or would I be better off just having the Array set to max size and manually blocking out the area that isn't available to the player yet.

  • The array can map 1:1 to the tile map. This sets up the array data, then fills in the tilemap from the array. The two are addressed in the same way. You can add rows and columns, but I think the simpler solution is just to define the whole array up front and use a Z index for the state.

    http://www.blackhornettechnologies.com/ ... lemap.capx

  • Why did you multiply the Value by 3? When setting up the Array values? Is that just something you did for an unrelated reason or am I missing something.

  • The tilemap is addressed by row&column. the frame/tile is addressed by number. Click on the tilemap tab and click the edit tool. Mouse over the tiles. You'll see the tile numbers go from 0 to 17.

  • When I changed the number and ran it I saw that it is needed for the proper order of the tiles. I am not sure of the reason however. I could only guess it has something to do with the Width of the Array.

  • That is how you calculate the tile number. The tiles are in rows of 3, so tile number 14 is 4*3 + 2 : row=4, column=2

  • I understand now. I was misunderstanding Loopindex

  • I am not understanding the 3 then. Because 0 + 0 *3 = 0 and 0 + 1 *3 = 3. I am not understanding it fully. I understand that loopindex is how many times to loop. What I am missing is, by multiplying by 3 it seems the array values would be multiples of 3, which should throw the tile order out. I understood what Loopindex means is what I meant by the above post.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I don't know how else to explain it. Column 0 and row 1 is tile number 3, as the editor shows. It may not matter, as you will be filling in the tile data through your own mechanism.

  • I admit I got the X and Y coordinates backwards for a small bit.

    X0Y0, X1Y0, X2Y0

    X0Y1, X1Y1, X2Y1

    X0Y2, X1Y2, X2Y2

    The formula loopindex("x") + loopindex("y") * 3 for the array value does work. The 3 is in fact the Width of the TileMap. By multiplying the Y by 3 it is correctly placing the values of the array in ascending order.

    It sets the values of the X to

    0,1,2

    0,1,2

    0,1,2

    and the values of the Y to

    0,0,0

    3,3,3

    6,6,6

    Any number multiplied by 0 is 0. So that explains how the top 3 tiles can stay 0,1,2 . When X and Y is added together it creates:

    0,1,2

    3,4,5

    6,7,8

    Thanks, the example you gave was very useful.

    I just figured I would explain in case more people need to know.

    I forgot you could view the Array Values in the Debugger as well.....

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