简体   繁体   English

Javascipt Canvas,我点击后去掉一个圆圈

[英]Javascipt Canvas, Remove a circle after I click on it

in this code i create a circle and put him where i want on canvas, i want to remove him after clicking on it and if i click again than display him, how i can do this?在这段代码中,我创建了一个圆圈并将他放在 canvas 上我想要的位置,我想在单击它后删除他,如果我再次单击而不是显示他,我该怎么做?

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您必须清除绘制圆圈的 canvas 部分

let canvas = document.getElementById("myCanvasID");
let context = canvas.getContext('2d');
context.clearRect(0, 0, canvas.width, canvas.height);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM