Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

kineticjs

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!

like image 926
Arturo E Avatar asked Dec 03 '22 02:12

Arturo E


1 Answers

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.

like image 81
Erfan Zarger Avatar answered May 16 '23 06:05

Erfan Zarger