Kinetic JS - How to get the coordinates of member of a group (after group has been dragged)?

Arturo E picture Arturo E · Aug 8, 2012 · Viewed 8k times · Source

I have a group of Kinetic.Rectangle objects with draggable set to true. No matter how much you drag the group around, calling rect.getX() or rect.attrs.x, where rect is one of the rectangle objects in the group, e.g.:

var rect = group.get('.rect')[0];

always returns the same value. Anybody know how the get the actual x and y values of where each rectangle is being drawn?

Thanks!

Answer

Erfan Zarger picture Erfan Zarger · Aug 8, 2012

I guess the reason that you get the same results is because you get the relative position of each rec. I usually use the following codes to get the position of my objects:

Shape.getAbsolutePosition().x

or

shape.getPosition().x

hope this would be helpful.