I want to detect clicks on canvas elements which are drawn using paths. So far I have stored element paths in a JavaScript data structure and then check the coordinates of hits which match the element's coordinates. Rendering each element path and checking the hits would be inefficient when there are a lot of elements. I believe there must be an algorithm for this kind of coordinate search, can anyone help me with this?
\$\begingroup\$
\$\endgroup\$
3
-
\$\begingroup\$ You can probably also try using pixel color for detection. As far i know EaselJS it in the algorithms \$\endgroup\$Vishwas– Vishwas2012-10-04 17:55:57 +00:00Commented Oct 4, 2012 at 17:55
-
\$\begingroup\$ If you can name any algorithm particulary for this purpose or steps instead of library it would be nice. \$\endgroup\$varuog– varuog2012-10-04 20:43:20 +00:00Commented Oct 4, 2012 at 20:43
-
\$\begingroup\$ I am not sure about the steps. But something like this : stackoverflow.com/questions/6735470/… can be used in the algorithm \$\endgroup\$Vishwas– Vishwas2012-10-05 05:17:59 +00:00Commented Oct 5, 2012 at 5:17
Add a comment
|
1 Answer
\$\begingroup\$
\$\endgroup\$
You should probably take a look at engines that already do that like:
But I'm pretty sure they maintain some state relative to position and shape and check against those for every frame update.