This is an isometric version of the in-built action "snap to a grid" (or move_snap() in GML.) Hope this is useful to someone, no credit is necessary.
The script
// Script: move_snap_isometric(hsnap, vsnap) // Purpose: snaps the instance to an isometric grid. // Inputs: // Â argument0 = the horizontal snapping value, i.e. the width of the grid. // Â argument1 = the vertical snapping value, i.e. the height of the grid. // Example: // Â move_snap_isometric(32, 16); var m, n; m = round(y/argument1 - x/argument0); n = round(y/argument1 + x/argument0); x = (n - m)/2*argument0; y = (n + m)/2*argument1;
Edit: An example
snap_isometric.gm6 (8KB)
How it works
m and n represents the indices of the diagonal-down and diagonal-up grid lines, respectively (see the figure below.) The former half of the script determines m and n of each line which is nearest to the given point, and the latter half calculates the position of intersect of grid lines with the given m and n.
Edited by torigara, 15 January 2011 - 04:40 PM.











