In this code I create a circle and put it where I want on canvas; I want to remove it after clicking on it and if I click again than display it. How I can do this?
var createCircle = new ShootyController();
createCircle.x;
createCircle.y;
createCircle.radius = 10;
createCircle.color = "red";
canvas.addEventListener(
"click",
function (e) {
createCircle.x = e.clientX;
createCircle.y = e.clientY;
createCircle.x -= canvas.offsetLeft;
createCircle.y -= canvas.offsetTop;
},
{once: true}
);
You have to clear the canvas part where your circle is drawing
let canvas = document.getElementById("myCanvasID");
let context = canvas.getContext('2d');
context.clearRect(0, 0, canvas.width, canvas.height);