Question

When ever I draw shape, I just call stage.draw() method, so the shapes are repeated once again. So My question is how to add shapes without more occurrence of previously drawn shapes.
Here sample code

//creating group for adding text
     var textGroup = new Kinetic.Group({
                    x: e.pageX,
                    y: e.pageY - posY,
                    draggable: true,
                    id: 'textgroup'
                });
                layer.add(textGroup);
                stage.add(layer);
                textname = 'text' + shapecount;
//creating text 
                var text = new Kinetic.Text({
                    x: 0,
                    y: 0,
                    text: comment,
                    fill: "#" + fillcolor,
                    fontSize: 24,
                    opacity: 0.5,
                    name: textname
                });
//adding text into group
                textGroup.add(text);
//finally drawing stage
                  stage.draw();


 Can anyone help me out?

    Thanks in Advance, 
Était-ce utile?

La solution

You could just call the draw() method on the group to which you added the shape. This will only redraw the shapes in that specific group. I.e. textGroup.draw()

In fact you can call the draw() method from any Node (including, Shapes, Layers, Stages, Groups etc).

Update

I made a fiddle http://jsfiddle.net/u9xHe/1/. Adding a Text shape, calling draw, then adding another Text shape and calling draw again. Nothing seems out of place in this case.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top