Experimento del kit de animación de lienzo ... ... ¿cómo limpiar el lienzo?
-
07-07-2019 - |
Pregunta
Puedo hacer un obj para usar el lienzo para dibujar así:
MyObj.myDiv = new Canvas($("effectDiv"), Setting.width, Setting.height);
Luego, uso esto para dibujar un rectángulo en el lienzo:
var c = new Rectangle(80, 80,
{
fill: [220, 40, 90]
}
);
var move = new Timeline;
move.addKeyframe(0,
{
x: 0,
y: 0
}
);
c.addTimeline(move);
MyObj.myDiv.append(c);
Pero después de dibujar el rectángulo, quiero borrar el lienzo, pero no sé qué método y cómo hacer esto ... ...
O ... una cosa más: es el sitio web de CAKE: Enlace
Solución
Borrar el lienzo:
canvas.clear = true; // makes the canvas clear itself on every frame
canvas.fill = somecolor; // fills the canvas with some color on every frame
// with canvas.clear = false and low-opacity fill, fancy motion blur effect
Removing the rectangle from the canvas:
rectangle.removeSelf();
or
canvas.removeChild(rectangle);
Otros consejos
Puedes probar este método:
MyObj.myDiv.clearRect(0, 0, canvas.width, canvas.height);
Que colorea efectivamente todo el lienzo en el color de fondo.
La forma más fácil es:
MyObj.myDiv.width = MyObj.myDiv.width;
Descubrí que cambiar el tamaño del lienzo funciona como magia, incluso si realmente no está cambiando el tamaño:
canvas.width = canvas.width
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow