Legacy GM Tile Rotation

Steneub

Member
The tile editor in 1.4 could be... better (I've used the much improved GMS2, but I don't have the license for it)

upload_2019-6-5_7-33-27.png

Is there a way to enable the "Rotation" flag per tile in the UI? Or maybe I could modify it with a function or raw editing of the XML in the *.room.gmx file?

I've taken to using third party editor "Tiled" and its easy-to-use rotations and flips, but the export doesn't include rotations either (...as if it already knows it's a lost cause...).

Is there a magical way of doing this, or do I need to adjust my workflow?
 

Steneub

Member
So I came up with something else. My solution is a little brute-force'y.

For context, I started a project in GMS2 and followed this isometric tutorial:
It basically takes grid 2d tiles and renders to isometric space. When building the base map in Tiled, it's tempting to use rotations for tiles, but I needed to make a 2d tileset that filled my needs without rotations because I know GMS1.4 doesn't support it.

What I ended up doing was taking 2d tiles, reading their x- and y-scaling, and mapping them to properly rendered isometric tiles with their own x- and y-scaling. Some tiles are one-to-one (i.e. 2d-tile 4 maps to iso-tile 6), but most have wonky mappings when you introduce the "rotations"

My result is good! The flat-source and isometric-rendering are both on-screen here, along with my 2 tile-set. I would be curious if there's a better way to do it more elegantly.
upload_2019-6-7_12-0-43.pngupload_2019-6-7_12-0-48.pngupload_2019-6-7_11-59-55.png

Code:
var tileIndex = argument0;
var tX = argument1;
var tY = argument2;
//////////////////////////////////////////////////////////////

var screenX = TileToScreenX(tX,tY);
var screenY = TileToScreenY(tX,tY);
  
var tLeft = tile_get_left(tileIndex) / TILE_SIZE;
var tTop = tile_get_top(tileIndex) / TILE_SIZE;            
var tXscale = tile_get_xscale(tileIndex);
var tYscale = tile_get_yscale(tileIndex);

var isoSpriteIndex = irandom(14);
var isoXscale = 1;
var isoYscale = 1;

switch (tTop) {
 
    case 0: switch (tLeft) {
        case 0:
        isoSpriteIndex = 8;
        break;
        case 2:
        isoSpriteIndex = 11;
        break;
        case 3:
        isoSpriteIndex = 2;
  
        if (tYscale == -1 && tXscale == 1) {
            isoSpriteIndex = 12;
        }
        else if (tYscale == 1 && tXscale == -1) {
            isoSpriteIndex = 12;
            isoXscale = -1;
            isoYscale = -1;
        }
        else {  
            if (tYscale == -1) isoYscale = -1;
            if (tXscale == -1) isoXscale = -1;
        }
        break;
    } break;
 
    case 1: switch (tLeft) {
        case 0:
        isoSpriteIndex = 0;
        if (tYscale == 1 && tXscale == -1) {
            isoSpriteIndex = 3;
            isoXscale = -1;
        }
        else if (tYscale == -1 && tXscale == 1) {
            isoSpriteIndex = 3;
        }  
        else if (tYscale == -1) isoYscale = -1;
        break;
  
        case 1:
        isoSpriteIndex = 1;
  
        if (tYscale == 1 && tXscale == 1) isoXscale = -1;
        else if (tYscale == 1 && tXscale == -1) {
            isoSpriteIndex = 9;
            isoXscale = -1;
        }
        else if (tYscale == -1 && tXscale == 1) {
            isoSpriteIndex = 9
            isoYscale = -1;
        }  
        else if (tYscale == -1 && tXscale == -1) {
            isoYscale = -1;
            isoXscale = 1;
        }
        else {  
            if (tYscale == -1) isoYscale = -1;  
            if (tXscale == -1) isoXscale = -1;
        }  
        break;
  
        case 2:
        isoSpriteIndex = 4;
  
        if (tYscale == 1 && tXscale == 1) isoXscale = -1;
        else if (tYscale == -1 && tXscale == 1) {
            isoSpriteIndex = 6;
            isoYscale = -1;
        }  
        else if (tYscale == 1 && tXscale == -1) {
            isoSpriteIndex = 6;
            isoXscale = -1;
        }
        else if (tYscale == -1 && tXscale == -1) {
            isoYscale = -1;
            isoXscale = 1;
        }
        else {
  
            if (tYscale == -1) isoYscale = -1;
            if (tXscale == -1) isoXscale = -1;
        }
        break;
  
        case 3:
        isoSpriteIndex = 5;
        if (tYscale == -1 && tXscale == 1) {
            isoSpriteIndex = 13;
        }
        else if (tYscale == 1 && tXscale == -1) {
            isoSpriteIndex = 13;
            isoXscale = -1;
            isoYscale = -1;
        }  
        else {
            if (tYscale == -1) isoYscale = -1;
            if (tXscale == -1) isoXscale = -1;
        }
        break;
          
        case 4:
        isoSpriteIndex = 1;
        if (tYscale == 1 && tXscale == -1) {
            isoSpriteIndex = 9;
            isoXscale = -1;
            isoYscale = -1;
        }
        else if (tYscale == -1 && tXscale == 1) {
            isoSpriteIndex = 9;
        }
        else {
            if (tYscale == -1) isoYscale = -1;
            if (tXscale == -1) isoXscale = -1;
        }
        break;  
  
    } break;
 
    case 2: switch (tLeft) {
        case 0:
        isoSpriteIndex = 2;
        if (tYscale == 1 && tXscale == -1) {
            isoSpriteIndex = 12;
            isoXscale = -1;
        }  
        else if (tYscale == 1 && tXscale == 1) {
            isoXscale = -1;
        }
        else if (tYscale == -1 && tXscale == 1) {
            isoSpriteIndex = 12;
            isoYscale = -1;
        }
        else if (tYscale == -1) isoYscale = -1;
        break;
 
        case 1:
        isoSpriteIndex = 5;
        if (tYscale == 1 && tXscale == -1) {
            isoSpriteIndex = 13;
            isoXscale = -1;
        }
        else if (tYscale == 1 && tXscale == 1) {
            isoXscale = -1;
        }
        else if (tYscale == -1 && tXscale == 1) {
            isoSpriteIndex = 13;
            isoYscale = -1;
        }  
        else if (tYscale == -1) isoYscale = -1;
        break;
 
        case 2:
        isoSpriteIndex = 7;
        if (tYscale == 1 && tXscale == -1) {
            isoSpriteIndex = 10;
            isoXscale = -1;
        }
        else if (tYscale == 1 && tXscale == 1) {
            isoXscale = -1;
        }
        else if (tYscale == -1 && tXscale == -1) {
            isoSpriteIndex = 7;
            isoYscale = -1;
        }
        else if (tYscale == -1 && tXscale == 1) {
            isoSpriteIndex = 10;
            isoYscale = -1;
        }    
        else {
            if (tYscale == -1) isoYscale = -1;
            if (tXscale == -1) isoXscale = -1;
        }
        break;
  
        case 3:
        isoSpriteIndex = 7;
        if (tYscale == -1 && tXscale == 1) {
            isoSpriteIndex = 10;
        }
        else if (tYscale == 1 && tXscale == -1) {
            isoSpriteIndex = 10;
            isoXscale = -1;
            isoYscale = -1;
        }
        else {
            if (tYscale == -1) isoYscale = -1;  
            if (tXscale == -1) isoXscale = -1;
        }
        break;
  
        case 4:
        isoSpriteIndex = 4;
        if (tYscale == 1 && tXscale == -1) {
            isoSpriteIndex = 6;
            isoYscale = -1;
            isoXscale = -1;
        }
        else if (tYscale == -1 && tXscale == 1) {
            isoSpriteIndex = 6;
        }
        else {
            if (tYscale == -1) isoYscale = -1;
            if (tXscale == -1) isoXscale = -1;
        }
        break;
    }
}

if (isoXscale = -1) screenX += TILE_W;
if (isoYscale = -1) screenY += TILE_H;
draw_sprite_ext(sprite2, isoSpriteIndex, screenX, screenY, isoXscale, isoYscale, 0, c_white, 1);
 
Last edited:
Top