Tilemap transformation matrix acting strange

i’m having really weird behavior loading in tilemaps.
i’m using tiled, exporting to a .lua file
the bitflags for the transformation matrix of tiles seems to be off.
there seems to be an erroneous addition of a flip sometimes

below are some test squares, rows from top to bottom: none, vertical flip, horizontal flip, both flips). columns from left to right: none, rotated clockwise once, twice, three times

how it shows up in tiled (how it should look):
Capture

how it shows up in game (not so good):
Capture2


my code for getting the transform matrix (and tile id too):

local function extracttile(tilenum)
	local tile=bit.band(0xFFFFFFF,tilenum)
	local flags=tilenum-tile
	flags=bit.rshift(flags, 28)
	local rflags=0
	local hf,vf,r9=false,false,false
	hf= (bit.band(flags,8)>1)   --hlfip
	vf= (bit.band(flags,4)>1) --vflip
	r9= (bit.band(flags,2)>1)  --rotation
	
	rflags=(hf and tilemap.H_FLIP or 0) + (vf and tilemap.V_FLIP or 0) + (r9 and tilemap.ROTATE_90 or 0)

	return tile,rflags
end


is the problem with defold not handling transforms correctly or is it with tiled not exporting properly, or is it my code being bad?

ok so for whatever reason, i have to give a tile whenever it is rotated, an additional vertical flip.
unless there’s already a vertical or horizontal flip, in which case i need to give it a horizontal flip
except if there’s both a vertical *and* horizontal flip, in which case i just use a vertical flip again.

why?

No idea. My head hurts trying to make sense of all of the flips and rotations :slight_smile: I suppose it also matter in which order the operations are applied. The flip or the rotation first? Depending on which one is done first the outcome will be different.

I suppose it also matter in which order the operations are applied.

that only applies to tiled, where the order of a flip/rotate will affect the actual tile transform (this is only done, from what i can tell at least, to make it more intuitive to use)
however, the transforms themselves are orderless, both in how they are saved in a tilemap (as a tiled .lua file, the 3 (4) highest bits) and how defold handles transforms (a series of bitflags you add together)