paper.js how to set up multiple canvases using only javascript

后端 未结 6 826
予麋鹿
予麋鹿 2021-02-13 21:31

I\'m trying to use paper.js in a webapp, but I\'ve been unable to get it to work with multiple canvases. It\'s like the scopes are getting mixed up between the canvases, so when

6条回答
  •  自闭症患者
    2021-02-13 22:38

    Use arrays to separated your papers.

    this.mypapers = []
    
    var mypaper = new paper.PaperScope();
    mypaper.setup($("myCanvasId")[0]);
    
    mypapers.push(mypaper);
    
    mypaper = new paper.PaperScope();
    mypaper.setup($("myCanvasId")[1]);
    
    mypapers.push(mypaper);
    
    var circle = new this.mypapers[0].Path.Circle(10,10,5);
    var circle2 = new this.mypapers[1].Path.Circle(10,10,10);
    

    EDIT: I've update your js fiddle: http://jsfiddle.net/94RTX/3/

    Apparently each setup erase the previous one, so the solution is to do it in this order:

    setup canvas 1-> draw canvas 1 -> setup canvas 2 -> draw canvas 2
    

提交回复
热议问题