Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
You can probably also try using pixel color for detection. As far i know EaselJS it in the algorithms – Vishwas G Oct 4 '12 at 17:55
If you can name any algorithm particulary for this purpose or steps instead of library it would be nice. – varuog Oct 4 '12 at 20:43
I am not sure about the steps. But something like this :… can be used in the algorithm – Vishwas G Oct 5 '12 at 5:17

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.