I have it when the player clicks the mouse they can move the peice aoround the board. I am trying to have the chess pieces snap to a grid after the mouse has been released. Is there any way to round numbers so that I can round the X and Y coordinates so that it will snap to the grid?
Answer
You will basically turn the position of your mouse click into an integer. To do this simply divide the coordinates obtained by the size of the grid you want to create (32 in my case).
Then just multiply by the same amount you divided (32 in my case).
Splitting has to be done using div
, no /
.
Create Event:
gridx=0;
gridy=0;
Global Left Pressed Event:
gridx=mouse_x div 32;
gridy=mouse_y div 32;
x=gridx*32;
y=gridy*32;
The way I suggested above is more didactic and simpler to change, but if you want it can be simply...
Global Left Pressed Event:
x=(mouse_x div 32)*32;
y=(mouse_y div 32)*32;
No comments:
Post a Comment