I'm trying to make something similar to osu where I can click on a disc and a new one pops up. Right now, whenever I click anywhere on the canvas a new disc appears and the old one is cleared. I need it to only happen when I click on the current disc. How can I accomplish this? To clarify it a bit, there will only be one disc on the screen at a time. Whenever I click on it, the canvas will be cleared and a new disc will be created on the canvas at random coordinates.
This is my javascript code so far:
var elem = document.getElementById('myCanvas');
elem.onclick = function(){
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.clearRect(0,0,1000,750);
ctx.beginPath();
var posx = Math.floor(Math.random() * 950);
var posy = Math.floor(Math.random() * 625)
ctx.arc(posx+25, posy+25, 25, 0, 2 * Math.PI);
ctx.stroke();
var myColors = ['blue', 'red', 'green', 'yellow', 'black', 'maroon'];
var selectedcolor = myColors[Math.floor(Math.random() * myColors.length)];
ctx.fillStyle = selectedcolor;
ctx.fill();
}