How to use multiple paperscopes on a single canvas in paperjs? -
i'm trying create multiple canvases each it's own scope. i've hit few problems didn't encounter when working single canvas , scope.
i have array of scopes , try switching between them using scopearray[n].activate();
seems not initiate paperscope.project
, can't assign layers or draw.
any in solving appreciated.
i set canvases based on size of array , store them in object:
paper.install(window); ... var paperpad = {}; var layers = { 'back': 0, 'draw': 1, 'control': 2, 'front': 3 } function setupcanvas(){ // init canvas , calculate width/height/centre for(var c in canvaslist){ var el = document.createelement("canvas"); var id = '' + canvaslist[c][0] + '' + canvaslist[c][1] + '' + canvaslist[c][2]; el.width = canvaswidth; el.height = canvasheight; el.setattribute('id', id); el.setattribute('class', 'padcanvas'); document.body.appendchild(el); paperpad[id] = new paper.paperscope(); paperpad[id].setup(el); }
and attempt automatically setup layers accessing project global error saying project null.
function setuplayers() {
for(var p in paperpad){ paperpad[p].activate(); project.layers[0].setname('back'); for(var l in layers) { if(!project.layers[layers[l]]){ var layer = new layer(); layer.setname(l); } } }
}
same happens in draw functions
function draw() {
for(var p in paperpad) { paperpad[p].activate(); // draw functions }
}
i'm sure there's i'm missing how scoping works.
paperjs not update global variable project
though you've installed paper globals via paper.install(window)
in pure javascript mode. if set project = paperpad[id];
should work. end using paper.project
, manually updating because started way , seems natural @ point.
but paper doesn't manage keeping project
up-to-date in javascript mode.
Comments
Post a Comment