hdarren
Member
I'm making a small strategy game on an orthogonal grid as you can see in the image below where each square is 24x11 pixels.
I'm trying to get the center pixel x/y co-ordinate for a specific tile that the mouse cursor is over so that I can do things like create a spell effect in the middle of the square, but I'm having a problem getting the precise x/y position because of how the square rows are offset.
I'm currently using the following code.
So this gets the current mouse pointer's x/y co-ordinate and attempts to round it to the central point of a grid square giving me the vx/vy variables for that (which you can see below where it shows an outlinded cell). But as you can see in the image below there's a problem with the offset row where it jumps too far to the right once it goes over the half-way point of a cell.
[gif]
I can't seem to figure out how to get the correct cell co-ordinates. Can anybody help with this?
I'm trying to get the center pixel x/y co-ordinate for a specific tile that the mouse cursor is over so that I can do things like create a spell effect in the middle of the square, but I'm having a problem getting the precise x/y position because of how the square rows are offset.
I'm currently using the following code.
GML:
vx = round(x/24) *24;
vy = round(y/6);
if is_multiple(vy,2) {vx += 12;}
vy *= 6;
[gif]
I can't seem to figure out how to get the correct cell co-ordinates. Can anybody help with this?
Last edited: