Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Instance "jumps" to mouse position

Explorer ,
Jul 26, 2020 Jul 26, 2020

Hello, guys!
I would like to know how to correct the code to prevent "jump" of instance (Y coords) to initial Mouse Down position. What should I add?

 

this.L.y = 430;
this.L.on("pressmove", function(evt) {
   let p = evt.currentTarget.parent.globalToLocal(evt.stageX, evt.stageY);
   //evt.currentTarget.x = p.x;
   evt.currentTarget.y = p.y;
   if (evt.currentTarget.y > 730) {
      evt.currentTarget.y = 730;
   } else if (evt.currentTarget.y < 430) {
      evt.currentTarget.y = 430;
   }
stage.update();
});

 

Thank you!

TOPICS
Code
262
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 26, 2020 Jul 26, 2020

Capture the X/Y difference between the mouse coordinates and the clicked symbol to a set of persistent variables, then subtract (or add) that difference when setting the symbol's dragged coordinates.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 26, 2020 Jul 26, 2020

Sure, I have done this with mouseclick. Then mouse down. How to do this within one code block?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 28, 2020 Jul 28, 2020
LATEST

Снимок экрана 2020-07-28 в 16.55.06.png

 

Bu the way, can you help me to understand how to put 'INCORRECT' movie clip straight to mouse coordinates? There are main window and inner movie clip. I want to get this "INCORRECT" opened only while click at panel_PA_anim with right coordinates.

 

this.panel_PA_anim.addEventListener("click", (e) => {
Object(this.parent).incorrect.x = this.panel_PA_anim.x + stage.mouseX;
Object(this.parent).incorrect.y = this.panel_PA_anim.y + stage.mouseY;
Object(this.parent).incorrect.visible = true;
});

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 26, 2020 Jul 26, 2020

I've fixed the problem in a such way. It works perfectly on iMac, but then doesn't work on iPad.

What's the problem?

 

createjs.Touch.enable(stage);

this.L.y = 430;
let offset = 0;

 

this.L.addEventListener("mousedown", (evt) => {
let a = evt.currentTarget.parent.globalToLocal(evt.stageX, evt.stageY);
offset = a.y - evt.currentTarget.y;
console.log('mouse clicked');
});

this.L.addEventListener("pressmove", (evt) => {
let p = evt.currentTarget.parent.globalToLocal(evt.stageX, evt.stageY);
//evt.currentTarget.x = p.x;
evt.currentTarget.y = p.y - offset;
if (evt.currentTarget.y > 730) {
evt.currentTarget.y = 730;
} else if (evt.currentTarget.y < 430) {
evt.currentTarget.y = 430;
}
stage.update();
});

this.L.addEventListener("touchstart",function(evt) {
evt.preventDefafult();
let a = evt.currentTarget.parent.globalToLocal(evt.stageX, evt.stageY);
offset = a.y - evt.currentTarget.y;
console.log('touched');
});

this.L.addEventListener("touchmove",function(evt) {
evt.preventDefafult();
let p = evt.currentTarget.parent.globalToLocal(evt.stageX, evt.stageY);
//evt.currentTarget.x = p.x;
evt.currentTarget.y = p.y - offset;
if (evt.currentTarget.y > 730) {
evt.currentTarget.y = 730;
} else if (evt.currentTarget.y < 430) {
evt.currentTarget.y = 430;
}
stage.update();
});

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 27, 2020 Jul 27, 2020

"Doesn't work" is uselessly vague. What exactly do you mean?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines