Skip to main content
3 of 3
deleted 22 characters in body
Jesse Dorsey
  • 2.9k
  • 4
  • 34
  • 59

How would I translate screen coordinates to Isometric coordinates?

I have a function isoToScreen(x, y) that converts Isometric coordinates to Screen coordinates.

var tileW = 16;
var tileH = 16;

var isoToScreen = function(x, y) {
    var posX = (x - y) * tileW;
    var posY = (x + y) * tileH / 2;

    return [posX, posY];
};

But how would I make a function that converts screen coordinates back to Isometric coordinates?

var pos = screenToIso(16, 8); 
pos[0] = 1; // Iso X
pos[1] = 0; // Iso Y
Veyha
  • 85
  • 1
  • 5