0

I am drawing objects into a canvas like this,

ctx.fillStyle = "black";
ctx.fillRect(player.x, player.y, player.width, player.height);

After I've drawn lots of them, I would like to deteremine whether something was drawn at a particular coordinates in the canvas , how can I accomplish this ?

Tomarinator
  • 782
  • 1
  • 11
  • 28
  • 3
    Take a look at the accepted answer: [Get pixel color from canvas, on mouseover](http://stackoverflow.com/questions/6735470/get-pixel-color-from-canvas-on-mouseover). You should be able to rework that to achieve what you want. – Matt Cain May 07 '13 at 09:01
  • As Matt pointed out, that answer fits your need. See its demo on [`jsFiddle`](http://jsfiddle.net/DV9Bw/1/) – Sam R. May 07 '13 at 09:10

1 Answers1

0

Things you draw on canvas are just pixels with no other properties, and therefore you cannot get anything from them. You can however make JSON object with coordinates and size of everything you have drawn, than make "for" loop to check if anything is among given coordinates.

Goran Lepur
  • 594
  • 1
  • 4
  • 15