Skip to main content
added 641 characters in body
Source Link
user1430
user1430

You can always index a 1D array with 2D semantics. Given the x and y you'd like to look up, if you know the width of the "2D" interpretation of the array, use the following indexing math:

var tile = array[y * width + x]

This will save you the hassle of converting.

If you must convert, and Tiled does not offer an option to export in the format you want, your best bet is to write a function to do it. This would look roughly like (in pseudo-code):

var result = new array[width][height];
for (var row = 0; row < height; ++row) {
  for (var column = 0; column < width; ++column) {
    result[column][row] = tiledLevelArray[row * width + column]
  }
}

Run your level through a function like this at initialization time; this way you do not have to manually fix up the Tiled-generated array every time you'd like to change it.

You can always index a 1D array with 2D semantics. Given the x and y you'd like to look up, if you know the width of the "2D" interpretation of the array, use the following indexing math:

var tile = array[y * width + x]

You can always index a 1D array with 2D semantics. Given the x and y you'd like to look up, if you know the width of the "2D" interpretation of the array, use the following indexing math:

var tile = array[y * width + x]

This will save you the hassle of converting.

If you must convert, and Tiled does not offer an option to export in the format you want, your best bet is to write a function to do it. This would look roughly like (in pseudo-code):

var result = new array[width][height];
for (var row = 0; row < height; ++row) {
  for (var column = 0; column < width; ++column) {
    result[column][row] = tiledLevelArray[row * width + column]
  }
}

Run your level through a function like this at initialization time; this way you do not have to manually fix up the Tiled-generated array every time you'd like to change it.

Source Link
user1430
user1430

You can always index a 1D array with 2D semantics. Given the x and y you'd like to look up, if you know the width of the "2D" interpretation of the array, use the following indexing math:

var tile = array[y * width + x]