Using GameMaker Language, I'm basing off their Adavnced Examples. How can i convert the current mouse position into a tile position?
The mouse coordinates are 0,0 from top-left
This is the function when it draws. I think this is what needs reversing. I'm tragically bad at Maths, so I'm sorry in advance.
/// DrawLevel()
var xx,yy,destx,desty, base_x,base_y,current_row_x,current_row_y,tile,o,sp, m,h,offy, tileset;
TileRowDX = 68;
TileRowDY = 34;
TileColumnDX = -68;
TileColumnDY = 34;
MapX = 0;
MapY = 0;
MapDrawX = 11;
MapDrawY = 11;
/// Draw the complete isometric level
tileset = global.tiles;
// End point in map drawing (map coordinates)
destx = MapX+MapDrawX;
desty = MapY+MapDrawY;
// Start drawing position - center in the middle of the screen - and just above a little
base_x = surface_get_width(application_surface)/2;
base_y = 150;
// X and Y loop to print all cells.
for( xx=destx-1;xx>=MapX;xx--) {
current_row_x = base_x;
current_row_y = base_y;
for( yy=MapY;yy<desty;yy++)
{
// First draw the column of tiles in this cell, bottom to top.
offy=0;
for(var h=0;h<global.mapMaxLayers;h++){
m = Map[h]; // get 2D map grid from level array (Z axis)
tile = m[# xx,yy]; // get tile from 2D grid (x,y axis)
if( tile>=0 ){
// if we have a tile, then draw it.
draw_sprite(tileset,tile,current_row_x,current_row_y-offy);
}
offy+=27;
}
// Next, get the object in this cell, and draw it on top.
// If allowing height for the player, you'd need to add on 27 for each block up.
o = Objects[# xx,yy];
if( o!=0 ){
// Get the object sprite to draw (could also do frames etc)
sp=o.Sprite;
// get a 0 to 1 value into the isometric cell.
var dx = (1.0/15.0) * ((o.x&15));
var dy = (1.0/15.0) * ((o.y&15));
// Move to top left of Isometrix grid cell
var ox = current_row_x - TileRowDX;
var oy = current_row_y - TileRowDY;
// Now convert into an isometric offset on X and Y
ox = ox + (dy*TileRowDX); //Y axis first
oy = oy + (dy*TileRowDY);
ox = ox - (dx*TileColumnDX); // now X axis
oy = oy - (dx*TileColumnDY);
// and draw this sprite
draw_sprite(sp,0,ox,oy);
}
// Move down and right
current_row_x += TileRowDX;
current_row_y += TileRowDY;
}
// Back up to top, and move left and down.
base_x += TileColumnDX;
base_y += TileColumnDY;
}
I'm sure this is just mostly a mathematics question!