Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

309
Views
How to make object jump to cursor/touch position on mousedown?

based on the createjs drag and drop demo, I'm trying to make it so that the circle jumps to the position of the cursor/touch on mousedown.

I managed to make the dragging work, but no idea how to make the circle jump to position.

createjs.Touch.enable(stage);

this.circle_mc.on("pressmove", function (evt) {
    var point = stage.globalToLocal(evt.stageX, evt.stageY)
    evt.currentTarget.x = point.x;
    evt.currentTarget.y = point.y;
    stage.update();
});

Can anyone help it do something like this?

enter image description here

Update: Managed to get it to work using this code in animate:

var _this = this;

stage.on("stagemousedown", function (evt) {
    var point = stage.globalToLocal(evt.stageX, evt.stageY)
    _this.circle_mc.x = point.x;
    _this.circle_mc.y = point.y;

    var moveAround = stage.on("stagemousemove", function (evt) {
        var point = stage.globalToLocal(evt.stageX, evt.stageY)
        _this.circle_mc.x = point.x;
        _this.circle_mc.y = point.y;
    });

    stage.on("stagemouseup", function (evt) {
        stage.off("stagemousemove", moveAround)
    }, null, true)
});
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can do this easily, but you have to re-make the dragmove, since by default it requires the mousedown on an object to kick it off. You also must reference the target directly instead of relying on an event target.

stage.on("stagemousedown", function(e){
    s.x = e.stageX; s.y = e.stageY;
  
  // Handle move
  var evt = stage.on("stagemousemove", function(e) {
    // Set to mouse position each move
    s.x = e.stageX; s.y = e.stageY;
  });
  
  // Handle release
  stage.on("stagemouseup", function(e) {
    stage.off("stagemousemove", evt)
  }, null, true)
});

Here is a quick fiddle with better comments. https://jsfiddle.net/lannymcnie/fn3gve74/1/

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!