Ok, to do it with the mouse, add a mousebutton down event, with drag enabled, and put
- Code: Select all
//
in script editor (or any other code you want).
In global code, add the function:
- Code: Select all
void SnapToGrid(int xsize, int ysize)
{
const int halfx = xsize / 2;
const int halfy = ysize / 2;
x = (round((x - halfx) / xsize) * xsize) + halfx;
y = (round((y - halfy) / ysize) * ysize) + halfy;
}
On mousebutton up, put
- Code: Select all
SnapToGrid(width, height);
or
- Code: Select all
SnapToGrid(xamount, yamount);
. Now it will move to a position with a gridn of size xamount by yamount, with it aligned inside the grid (So if it is close to zero, its corner will be on 0,0). If you want it aligned on top of the grid (so its center will be at 0,0) take out the xsize and ysize bits.