Tiles is rotated right and flip horizontal when export the position

After drawing the map, I want to export the position of tiles according to the green line as shown below:
tiles

Here are the map properties that I use (I use the default value):
Map properties

This is my export code:

const textPlainFormat = {
	name: "Text Plain",
	extension: "txt",
	write: function(map, fileName) {
		var unpassList = [];
		for(let i = 0; i < map.layerCount; ++i) {
			var layer = map.layerAt(i);
			if(layer.isTileLayer) {
				for(let y = 0; y < layer.height; ++y) {
					for(let x = 0; x < layer.width; ++x) {
						var tile = layer.tileAt(x, y);
						if(tile != null) {
							var isUnpass = tile.property("Unpass"); // The "Unpass" property is the Custom Properties of the tiles and data type is Boolean
							if(isUnpass) {
								unpassList.push(x);
								unpassList.push(y);
							}
						}
					}
				}
			}
		}
		var file = new TextFile(fileName, TextFile.WriteOnly);
		file.write('Unpass List = ' + JSON.stringify(unpassList));
		file.commit();
	},
}
tiled.registerMapFormat("txt", textPlainFormat)

When using the above code, the “Unpass” position that I received was rotate right then flip horizontal, formed a red square line instead of the green line.
How do I change the code to be able to export the position like a green line (not rotate right then flip horizontal)?

It looks like you’ve mixed up your x and y at some point, perhaps just swapping your inner and outer loops might fix it? Or, perhaps when you’re reading the data in the end, you’re using a different x/y order.

I want to export their position in the form of: x, y, x, y, x, y,… (1D arrays) I’m not sure if it is disturbed or not because if the rotate right then flip horizontal the position received from export, I’ll get the picture with the same position as I desire.

The position of the red tiles is consistent with rendering the red tiles with the x and y reversed, so make sure you’re interpreting your data correctly after you write it out, when you place the red tiles.

1 Like

But are you then rendering that data correctly?

Well I have found the problem. It was true that I reversed the position of X and Y, after turning the position into Y and X, it outlined the right position.