TL;DR somebody with the maths, looks at my capx and tell me why it doesn't snap right. please and thanks!
https://drive.google.com/file/d/0B1Aaz61BSeUDcDVKd1Q2VWVZeFk/view?usp=sharing
I'm making an isometric tile editor (using sprites) and I just want my sprites to snap on the staggered isometric grid.
I know there are lots of ways to do this. But I feel like there has to be a simple, 1-2 line way to do it, and that's what I'm looking for.
I figure if
set tile position: (mouse.x-mouse.x%128)
snaps it on a square grid, then I just need to take it one step further and have it check if the Y is on an even or odd row and then add the stagger (64px=half a tile) or don't. And then vice versa for the Y.
I keep coming up with something that looks kinda like this:
set tile position:
X: ((mouse.x-mouse.x%128)+(64*(round(mouse.y/64)%2)),
Y: ((mouse.y-mouse.y%64)+(32*(round(mouse.x/128)%2))
so the first half sets it on a square grid, and the second half checks if the opposite axis is odd or even (0 or 1 from the %2) and then moves it over the extra pixels if necessary.
At least that's what I think it should do. It almost does, but not really. heh.
Can anyone tell me where I'm going wrong, or why it doesn't work, or something?
Thanks!