HTML5 clicking objects in canvas

Posted by Dave on Game Development See other posts from Game Development or by Dave
Published on 2012-03-14T03:31:00Z Indexed on 2012/04/15 23:47 UTC
Read the original article Hit count: 237

Filed under:
|

I have a function in my JS that gets the user's mouse click on the canvas.

Now lets say I have a random shape on my canvas (really its a PNG image which is rectangular) but i don't want to include any alpha space.

My issue lies with lets say i click some where and it involves a pixel of one of the images. The first issue is how do you work out the pixel location is an object on the map (and not the grass tiles behind).

Secondly if i clicked said image, if each image contains its own unique information how do you process the click to load the correct data.

Note I don't use libraries I personally prefer the raw method. Relying on libraries doesn't teach me much I find.

© Game Development or respective owner

Related posts about JavaScript

Related posts about canvas