I need to develop a game using HTML 5 and Javascript with the game being within canvas
.
I created a game opening screen and after clicking play it goes to another screen. I called this event click
document.getElementById('canvas').addEventListener('click', verificaClick, false);
Where canvas
is the id of my canvas and verificaClick
the function that sends to the next step according to the selected option because I have the options "play", "how to play" and "credits".
If I click play it directs you to a page where I choose the "phase" or "step" of the game I want to play, more or less like Candy Crush.
My problem is that the canvas redraws everything correctly, however it remains the click event of the first part of the game, from the first canvas drawing. I'm redesigning, deleting context and redrawing, but the same click remains on the positions of the first "buttons" I drew.
Is the section where I call the click event correct?
document.getElementById('canvas').addEventListener('click', verificaClick, false);
If not, how should I do it; Put multiple contexts and add the event in context? How would you do that?