Working with flipped objects on tiled
-
I'm working with tiled for the levels and I want to use the Flipping variable to know if an object is flipped. I'm not sure how it works because that variable seems to change the Gid of the object.
I'm using the gid to know which object is each one but when I flip it changes.For example, an object without flip can have a gid that is: 4372 and the same object flipped have the gid: 2147488019
On TiledObject.hx I have functions to know if an object is flipped but I want to also know the gid before the flip so I can know which object is.
I'm not sure if this is something that I'm supposed to handle on my code or maybe there is something I'm missing.
This can be tested on the tiled demo: https://github.com/HaxeFlixel/flixel-demos/tree/dev/Editors/TiledEditor
I also made a github issue because I think this is something that has to be fixed from the exporter.
-
I never used flipped tiles, but you should read the gid as hex value, with high bits meaning the flipping type - horizontal, vertical and diagonal. Diagonal is 90 degree rotation (combined with horizontal and vertical you also get 180 and 270)
-
the tiled dev gets into the issue a bit here: http://doc.mapeditor.org/reference/tmx-map-format/#tile-flipping
it's not a bug, just the way that information is stored (definitely confusing tho)
there's some pseudo code at the link that you can port to haxe and use on your level loader to extract the proper gid and flip h/v values
-
Thanks for your help!
But still I'm very lost with this. How can I know which one is the original Gid?
I think that it is better if it is already done by the importer from flixel addons and not the user.
-
(0x0fffffff & gid)
-
Can you point me to some guide about how this kind of numbers work?
I actually found a bug with how this is done by HaxeFlixel. TiledObject.hx from Flixel addons:
// object with tile association? if (source.has.gid && source.att.gid.length != 0) { trace("gid lenght " + source.att.gid.length); gid = Std.parseInt(source.att.gid); for (set in layer.map.tilesets) { shared = set.getPropertiesByGid(gid); if (shared != null) { break; } } trace("shared " + shared); // If there is a gid it means that it's a tile object objectType = TILE; }
Here it sets the gid and takes the shared properties from the tileset. But if the tile object is flipped the shared properties are null.
-
@starry-abyss said in Working with flipped objects on tiled:
(0x0fffffff & gid)
Thanks but this is not givin me the value of the original Gid.
-
we actually spent quite a bit trying to get this done a while ago and we got stuck and ended up not using tiled's flip toggles cos there were issues with the precision of 32 bit ints vs 64 bit, and a conversion that worked on linux would not work in windows. i think it was specifically an issue with horizontal flips? can't remember atm
i'm not good at this stuff either, so i think there might be a better solution to the issue but i feel like making a custom exporter for tiled that just creates two extra custom properties might be better, or just have conditionals that parse the gid differently depending on platform
it's kind of a headache, really
i'll try and find our old gid parsing code for you and see if it's at least a good starting point
(edited: terrible writing)
-
Thanks!
The code can be useful for me.
I'm starting to read this articles about hexadecimal numbers to see if I can figure it out.
https://code.tutsplus.com/articles/understanding-bitwise-operators--active-11301
-
This was fixed. Thanks for your help and @Gama11's help.