Coffeehouse Post

Single Post Permalink

View Thread: Getting images created in a Canvas context to respond to an event
  • User profile image

    Hello, I am creating a rudimentary game for educational purposes.  I simply want to show at random intervals of time (up to 3 seconds) 1 to all images in a 5 image array.  The images will display at random locations within the canvas.  The images will disappear in random intervals of time (up to 3 seconds).  If the user clicks on an image before it disappears a running score is displayed and the image lights up with a yellow border.  I am using CSS for class types to light up if the image is clicked.  I can addEventListeners to the various images created and I set the className as appropriate.  I use ctx = canvas.getContext("2d") and ctx.drawImage to show the image.  The image is never getting the event.  Any code snippet to help me out?  Maybe I am barking up the wrong tree using Canvas?  I am hoping the experts in the coffee house can show me the code snip for this very simple example.  codeShow samples do not quite have the pieces for this.  Thanks