Hi all.
I am trying to do something relatively simple. I want the mouse position to “snap” a sprite called highlight to a grid.
In a top left world, this works…
highlight.x = ((this.mouseX) - (this.mouseX%gridRes));
highlight.y = ((this.mouseY) - (this.mouseY%gridRes));
The problem is, that for multiple reasons, i need to use a centered grid. I have drawn the grid correctly but the snapping is weird now and does not work correctly. It snaps to the center of my grid squares and not the corners. This has something to do with me now having negative values on my grid but no idea how to fix it because i do not really understand the Modulus operator anyway far less negative values.
Can you help?
Cheers.