简体   繁体   中英

Canvas Animation Kit Experiment… …how to clear the canvas?

I can make a obj to use the canvas to draw like this:

MyObj.myDiv = new Canvas($("effectDiv"), Setting.width,  Setting.height);

Then, I use this to draw a rectangle on the canvas:

    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);

But after I draw the rectangle, I want clear the canvas, but I don't know which method and how to do this... ...

O...one more thing: it is the CAKE's web site: Link

Clearing the canvas:

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);

You can try this method:

MyObj.myDiv.clearRect(0, 0, canvas.width, canvas.height);

Which effectively colours the entire canvas in the background colour.

最简单的方法是:

MyObj.myDiv.width = MyObj.myDiv.width;

我发现调整画布的大小就像魔术一样,即使你没有真正改变大小:

canvas.width = canvas.width

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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