Domanda

I have a Kinetic.Stage and 2 layers: layer1 and layer2. I drag elements from layer1 to drop them in layer2, knowing that I made a design of a grid in layer2. I need to clone layer2 in its initial state, I mean without the shapes and images that have been drawn on it, just an empty grid.

document.getElementById('buttonAdd').addEventListener('click', function () {        
    var cloneLayer = layer2.clone({id: layer2.attrs.id + 1});
    cloneLayer.draw();
    stage.draw();
});

This code clones the whole thing: the layer and its children. What should I add, in order to remove children?

Things I tried and failed:

  • cloneLayer.destroyChildren();

  • var x = cloneLayer.getChildren(); x.hide();

È stato utile?

Soluzione

"...just an empty grid". You can always create an empty grid with:

var newLayer=new Kinetic.Layer();
stage.add(newLayer);
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top