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

后端 未结 6 903
予麋鹿
予麋鹿 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:17

    @freejosh's answer works great for 10.2, but the fiddle still re-uses one canvas when upgrading to the latest version (12.2 as of now):

    http://jsfiddle.net/ecneto/86qckn2h/1/

    It's a simple fix, you can either downgrade, or make use of scope.activate(), which is feels a lot better than overriding paper:

    http://jsfiddle.net/ecneto/n91rdp6z/2/

    mypapers[0].activate();
    var circle1 = new paper.Path.Circle(30, 30, 20);
    circle1.style = {
        fillColor: new paper.Color(1, .5, .5),
        strokeColor: "black"
    };
    
    mypapers[1].activate();
    var circle2 = new paper.Path.Circle(60, 60, 20);
    circle2.style = {
        fillColor: new paper.Color(.5, .5, 1),
        strokeColor: "black"
    };
    

提交回复
热议问题