0

I'm just starting with KineticJS, and as in the title, I can't add a shape to a layer if that layer is already added to the stage. This is probably for a reason, but I'd like to understand why.

This works:

        var stage = new Kinetic.Stage({container: 'canvas', width:200, height:200});
        var layer = new Kinetic.Layer();
        var shape = new Kinetic.Wedge({x: 50, y: 50, radius: 30, angle: 60, fill: 'red'});
        layer.add(shape);
        stage.add(layer);

This doesn't:

        var stage = new Kinetic.Stage({container: 'canvas', width:200, height:200});
        var layer = new Kinetic.Layer();
        stage.add(layer);
        var wedge = new Kinetic.Wedge({x: 50, y: 50, radius: 30, angle: 60, fill: 'red'});
        layer.add(wedge);
user888734
  • 3,797
  • 5
  • 36
  • 67

1 Answers1

0

That is not correct. It must work in both ways, you're probably just missing stage.draw() after adding the shape in the second case.

Edit 1: For further reading regarding the draw() method, please refer to this link

Community
  • 1
  • 1
pgrodrigues
  • 2,083
  • 1
  • 24
  • 28
  • To elaborate, when you add a layer to the stage, it automatically draws the layer. When you add a shape to a layer, it does not automatically draw the layer. – Charles Ofria Jul 09 '14 at 02:31