Not an answer, but just to avoid future edge cases: make sure you clear the hexagonal 120-degree rotation flag (0x10000000
) too. It’s unlikely to creep into your map data if you never mess with hexagonals, but it does stick around if you switch data from hex to orthogonal, and it’s easy to miss that it’s there. Better safe than sorry. If it gets into your data and doesn’t get cleared, you’ll end up with invalid tile IDs.
Here’s the C++ code from my project that handles flips and rotations.
//hflip, vdlip, and dflip are bools obtained by checking the flags
//topLeft, topRight, botLeft, botRight are vectors containing texture coordinates for the current tile. They're initialised to the untransformed tile's coordinates.
if(dflip) {
temp = topRight;
topRight = botLeft;
botLeft = temp;
}
if(hflip) {
temp = topLeft;
topLeft = topRight;
topRight = temp;
temp = botLeft;
botLeft = botRight;
botRight = temp;
}
if(vflip) {
temp = topLeft;
topLeft = botLeft;
botLeft = temp;
temp = topRight;
topRight = botRight;
botRight = temp;
}
As you can see, in mine, I’m not applying transformations, I’m swapping texture coords around, since I use a fairly low-level representation of tiles (to make drawing faster). I find it easier to think about in terms of flips than rotations.
The diagonal flip should be done first. Otherwise, the coordinates you need to swap will change based on the combination of vertical and horizontal flips.
If rotations are the only thing you have access to and can’t just move the texture coordinates around to flip stuff, then the mistake you’re making might be the order. First, do the diagonal check, rotate and THEN flip*. After that, do the horizontal and vertical flips.
init currentTransform
if(dflip)
currentTransform.rotate(90) //90 degrees clockwise. If in your engine y points up, then this may need to be 270 instead of 90.
currentTransform.scale(-1, 1)
if(hflip)
currentTransform.scale(-1, 1)
if(vflip)
currentTransform.scale(1, -1)
* in this example, I rotated 90 degrees clockwise and a horizontal flip. 90 degrees counterclockwise and a vertical flip also works. Just make sure the order is correct.