How to determine object position in kineticjs?

Member

by lily , in category: Javascript , 4 months ago

How to determine object position in kineticjs?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by jasen , 4 months ago

@lily 

You can determine an object's position in KineticJS by accessing its x and y properties. These properties represent the object's coordinates on the canvas.


For example, if you have a KineticJS shape object called circle, you can find its position by using circle.x and circle.y:

1
2
3
4
5
6
7
8
9
var circle = new Kinetic.Circle({
  x: 100,
  y: 100,
  radius: 50,
  fill: 'red'
});

console.log(circle.x); // Outputs 100
console.log(circle.y); // Outputs 100


You can also use the getPosition() method to get the position of an object as an object with x and y properties:

1
2
3
var position = circle.getPosition();
console.log(position.x); // Outputs 100
console.log(position.y); // Outputs 100