snap to cursor on click
This commit is contained in:
parent
ac81079c5a
commit
a546fe38b7
@ -77,18 +77,16 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function handleCanvasClick(event) {
|
function handleCanvasClick(event) {
|
||||||
// If we're about to turn off tracking, update position one last time
|
// Update position at click location before toggling tracking
|
||||||
if (trackHover) {
|
const rect = canvas.getBoundingClientRect();
|
||||||
const rect = canvas.getBoundingClientRect();
|
const mouseX = event.clientX - rect.left;
|
||||||
const mouseX = event.clientX - rect.left;
|
const mouseY = event.clientY - rect.top;
|
||||||
const mouseY = event.clientY - rect.top;
|
|
||||||
|
|
||||||
// Add half grid unit offset for snapping to closest grid intersection
|
// Add half grid unit offset for snapping to closest grid intersection
|
||||||
userPoint = {
|
userPoint = {
|
||||||
x: Math.floor((mouseX + GRID_SIZE / 2) / GRID_SIZE),
|
x: Math.floor((mouseX + GRID_SIZE / 2) / GRID_SIZE),
|
||||||
y: Math.floor((HEIGHT - mouseY + GRID_SIZE / 2) / GRID_SIZE)
|
y: Math.floor((HEIGHT - mouseY + GRID_SIZE / 2) / GRID_SIZE)
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
trackHover = !trackHover;
|
trackHover = !trackHover;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user