# Tiles is rotated right and flip horizontal when export the position

**URL:** <https://discourse.mapeditor.org/t/tiles-is-rotated-right-and-flip-horizontal-when-export-the-position/5408>\
**Category:** Questions\
**Created:** [December 30, 2021, 3:49pm UTC](https://discourse.mapeditor.org/t/tiles-is-rotated-right-and-flip-horizontal-when-export-the-position/5408 "2021-12-30T15:49:43Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![TanQuang](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.mapeditor.org/tanquang/32/3561_2.png) [@TanQuang](https://discourse.mapeditor.org/u/TanQuang)\
**Post date:** [December 30, 2021, 3:49pm UTC](https://discourse.mapeditor.org/t/tiles-is-rotated-right-and-flip-horizontal-when-export-the-position/5408/1 "2021-12-30T15:49:43Z")

</div>

After drawing the map, I want to export the position of tiles according to the green line as shown below:  
 ![tiles](https://canada1.discourse-cdn.com/flex035/uploads/mapeditor/original/2X/f/f603fbcb727a99fb40a628a2d962cac7815f5de2.png)

Here are the map properties that I use (I use the default value):  
 ![Map properties](https://canada1.discourse-cdn.com/flex035/uploads/mapeditor/original/2X/4/44276a384747f98f5440cc73535fcaa771c01336.png)

This is my export code:

```auto
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)?

---

<div class="post-metadata">

**Author:** ![eishiya](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.mapeditor.org/eishiya/32/2534_2.png) [@eishiya](https://discourse.mapeditor.org/u/eishiya)\
**Post date:** [December 30, 2021, 4:36pm UTC](https://discourse.mapeditor.org/t/tiles-is-rotated-right-and-flip-horizontal-when-export-the-position/5408/2 "2021-12-30T16:36:49Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![TanQuang](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.mapeditor.org/tanquang/32/3561_2.png) [@TanQuang](https://discourse.mapeditor.org/u/TanQuang)\
**Post date:** [December 31, 2021, 2:11am UTC](https://discourse.mapeditor.org/t/tiles-is-rotated-right-and-flip-horizontal-when-export-the-position/5408/3 "2021-12-31T02:11:04Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![eishiya](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.mapeditor.org/eishiya/32/2534_2.png) [@eishiya](https://discourse.mapeditor.org/u/eishiya)\
**Post date:** [December 31, 2021, 3:45pm UTC](https://discourse.mapeditor.org/t/tiles-is-rotated-right-and-flip-horizontal-when-export-the-position/5408/4 "2021-12-31T15:45:14Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![eishiya](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.mapeditor.org/eishiya/32/2534_2.png) [@eishiya](https://discourse.mapeditor.org/u/eishiya)\
**Post date:** [December 31, 2021, 11:06pm UTC](https://discourse.mapeditor.org/t/tiles-is-rotated-right-and-flip-horizontal-when-export-the-position/5408/6 "2021-12-31T23:06:17Z")

</div>

But are you then rendering that data correctly?

---

<div class="post-metadata">

**Author:** ![TanQuang](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.mapeditor.org/tanquang/32/3561_2.png) [@TanQuang](https://discourse.mapeditor.org/u/TanQuang)\
**Post date:** [January 1, 2022, 3:08am UTC](https://discourse.mapeditor.org/t/tiles-is-rotated-right-and-flip-horizontal-when-export-the-position/5408/7 "2022-01-01T03:08:46Z")

</div>

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.
