Skip to main content
Participant
January 10, 2019
Answered

Pin child image roatation and translation

  • January 10, 2019
  • 1 reply
  • 260 views

Hello community,
I am working on a project that have a protractor image and a rotation-handle image for the protractor.

The rotation-handle rotates the protractor.

rotationHandle.on("mousedown", function (evt) {

     this.parent.addChild(this);

     this.offset = {

          x: this.x - evt.stageX,

          y: this.y - evt.stageY

     };

});

rotationHandle.on("pressmove", function (evt) {

     this.x = evt.stageX + this.offset.x;

     this.y = evt.stageY + this.offset.y;

     protractor.rotation = rotationHandle.rotation = Math.atan2(protractor.y - this.y, protractor.x - this.x) * 180 / Math.PI;

});

The issue is that when I move  the protractor, I need to move the rotation-image too.

protractor.on("mousedown", function (evt) {

     this.parent.addChild(this);

     this.offset = {

          x: this.x - evt.stageX,

          y: this.y - evt.stageY

     };

});

protractor.on("pressmove", function (evt) {

     this.x = evt.stageX + this.offset.x;

     this.y = evt.stageY + this.offset.y;

});

can anybody please tell me how to achieve that.
Thanks.

    This topic has been closed for replies.
    Correct answer kglad

    assign its offeset in mousedown and its x and y in pressmove.

    1 reply

    kglad
    Community Expert
    kgladCommunity ExpertCorrect answer
    Community Expert
    January 10, 2019

    assign its offeset in mousedown and its x and y in pressmove.