How to clear the canvas for redrawing

后端 未结 23 3389
粉色の甜心
粉色の甜心 2020-11-21 11:37

After experimenting with composite operations and drawing images on the canvas I\'m now trying to remove images and compositing. How do I do this?

I need to clear th

23条回答
  •  清歌不尽
    2020-11-21 12:09

    These are all great examples of how you clear a standard canvas, but if you are using paperjs, then this will work:

    Define a global variable in JavaScript:

    var clearCanvas = false;
    

    From your PaperScript define:

    function onFrame(event){
        if(clearCanvas && project.activeLayer.hasChildren()){
            project.activeLayer.removeChildren();
            clearCanvas = false;
        }
    }
    

    Now wherever you set clearCanvas to true, it will clear all the items from the screen.

提交回复
热议问题