Lets assume I generate many randomly positioned words in canvas. I want to be able to detect which text im hovering over. How is this done technically? I mean I am familiar with mouse circle collisions but not with text.
I assume I also have to use the pythagoras distance formula:
Here a more complete jsfiddle: https://jsfiddle.net/testopia/o7gL6ge9/1/
text = {
x: 50,
y: 100
}
function collision(m1, m2, textPos) {
var x = m1 - text.x;
var y = m2 - text.y;
return Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2));
}
if (collision(event.clientX, event.clientY, text) < 10) {
console.log('Hello World');
}