Zach
Zach

Reputation: 429

Finding the fill color of a draggable shape with Kineticjs

I have two circles with different colors and I want to get the fill color of the dragged circle once the user has let go of the object using the dragend event.

shapes = new Kinetic.Layer();

circle1 = new Kinetic.Circle({
   x: stage.getWidth() / 3.2,
   y: stage.getHeight() / 3.2,
   radius: radius,
   fill: "blue",
   stroke: "black",
   strokeWidth: 4,
   name: "circle",
   draggable: true
});  

circle2 = new Kinetic.Circle({
   x: stage.getWidth() / 1.5,
   y: stage.getHeight() / 1.4,
   radius: radius,
   fill: "yellow",
   stroke: "black",
   strokeWidth: 4,
   name: "circle",
   draggable: true
 });  

 shapes.add(circle1);
 shapes.add(circle2);
 stage.add(shapes);

Upvotes: 0

Views: 502

Answers (1)

Joseph
Joseph

Reputation: 119847

You can add a handler to the shape and use getFill()

function iGetFill(){
    var color = this.getFill();
}

circle1.on('dragend',function(){
    iGetFill.apply(this);
});

circle2.on('dragend',function(){
    iGetFill.apply(this);
});

Upvotes: 1

Related Questions