GML [SOLVED] mouse_x / 32 * 32, mouse_y / 32 * 32

Amon

Member
I'm trying to make the sprite attached to my mouse's x, y coords move in a grid like movement. I remember coding it this way a long time ago in a different language by doing this.. mouse_x / 32 * 32, mouse_y / 32 * 32

I cannot get it to work in GML though.

Can anyone point me in the right direction?
 
H

Homunculus

Guest
Try using DIV instead of / , or floor() the result of the division. Your code works only in languages where dividing two integers does not cause the result to be cast to a float (like ruby).
 
EDIT:
Dunno if I'm misunderstanding the issue :)

I can't recall if you can change the default mouse cursor to a sprite, but the issue would still be that it's attached to the x / y of the mouse, and that isn't a variable you can change.

To use those coordinates and yet alter them would I think require an object setting its x / y to mouse_x / y and then doing:
x = mouse_x / 32 * 32
y = mouse_y / 32 * 32

You might want to change the divide into div, as it returns only the amount it can be divided by 32. Which would give you the grid movement, whereas using divide would return an amount that isn't rounded off.
 
Top