tileWidth is 64 and tileHeight is 32.
This is my map array:
var map:Array=
[
[2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2],
[2,3,1,3,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2],
[2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2],
[2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2],
[2,2,2,2,2,2,2,2,2,2,3,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2]
];
Here is how theyre being placed:
//place tiles
for (var i:Number = 0; i < map.length; i++)
{
for (var j:Number = 0; j < map[i].length; j++)
{
placeTile(map[i][j],i,j);
}
}
//place the tile based on coordinates
private function placeTile(id:uint,i:uint,j:uint)
{
var pos:Point=new Point();
pos.x = i;
pos.y = j;
pos = twoDToIso(pos);
tile = new MovieClip(atlas.getTextures(getTile(id)),20);
tile.x = pos.x ;
//tile.y = pos.y + (map.length/2)*tileHeight - tileHeight*4 ;//used to center
tile.y = pos.y;
tile.addEventListener(TouchEvent.TOUCH, mapDown);
mapContainer.addChild(tile);
}
This is the function used to plot out the 2d points to isometric:
//CONVERT POINT TO ISOMETRIC
private function twoDToIso(pt:Point):Point
{
trace(" ");
trace("twoDtoIso:");
trace("2d: " + pt);
var tempPt:Point = new Point(0,0);
tempPt.x = (pt.x * tileWidth / 2) + (pt.y * tileWidth / 2);
tempPt.y = (pt.y * tileHeight / 2) - (pt.x * tileHeight / 2);
trace("iso: " + tempPt);
return (tempPt);
}
What formula can I use to revert the coordinates I receive when clicking a tile, back to 2d / access to the map array?