user1499220
user1499220

Reputation: 419

how to set coordinates, id and offset for a Kinetic Image

I have a kinetic image in my drawImage function:

var kImage = new Kinetic.Image({
          id: 'myImage',
          x: 200,
          y: 50,
          image: imageObj,
          width: 106,
          height: 118
        });

Now, I need to put kImage as a global varible, and set x, y, id... in the drawImage function.

I did:

function drawImage() {
    kImage.setX= ...
    kImage.setId=... 
}

but it seems that the kImage that I get in the end is "empty". kImage.getX() returns 0 for example and it is the same thing for the other fields.

Could you tell me what's wrong here please?

Thanks!

Upvotes: 1

Views: 533

Answers (1)

projeqht
projeqht

Reputation: 3160

Set Coordinates

kImage.setX(x) and kImage.setY(y)

or

kImage.setPosition(x, y)

Set ID

kImage.setId(id)

Set Offset

kImage.setOffsetX(x) and kImage.setOffsetY(y)

or

kImage.setOffset(x, y)

Sources

Kinetic.Shape#setX

Kinetic.Shape#setY

Kinetic.Shape#setPosition

Kinetic.Shape#setId

Kinetic.Shape#setOffsetX

Kinetic.Shape#setOffsetY

Kinetic.Shape#setOffset

Upvotes: 2

Related Questions