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

163
Views
Drag object around a half circle on mouse over - Adobe Animate HTML5 Canvas

I have the following code in Adobe Animate HTML5 Canvas using JavaScript/Easel.js/Create.js. The code enables an object to be dragged around a circle.

I now want to change this to function for a half circle, the top half. The object needs to be moved CW and CCW, and stop at the ends of the half circle (so backwards and forwards, but not right around a circle).

stage.enableMouseOver();

var knob_X = 454;
var knob_Y = 169;
var radius = 80;
var streakAngle;


root.streakRotatorKnob.addEventListener("mouseover", mouseOverKnob.bind(this));

root.streakRotatorKnob.x = knob_X + radius * Math.cos(0);
root.streakRotatorKnob.y = knob_Y + radius * Math.sin(0);

function mouseOverKnob(evt)
{
    root.streakRotatorKnob.addEventListener("pressmove", moveF);
}


function moveF(evt) { 
    var rads = Math.atan2(stage.mouseY - knob_Y, stage.mouseX - knob_X);
    var atan_knob = Math.atan2(evt.currentTarget.y, evt.currentTarget.x);
    evt.currentTarget.x = knob_X + radius * Math.cos(rads);
    evt.currentTarget.y = knob_Y + radius * Math.sin(rads);
    stage.update();
    console.log(atan_knob);
    
    streakAngle = Math.round(((rads * 180 / Math.PI) * 100) / 100);
    if (leye == true) {
        root.streakMainLeft.rotation = streakAngle + 90;
    } else if (reye == true) {
        root.streakMainRight.rotation = streakAngle + 90;
    }
    root.streakAngle.text = streakAngle + "\u00B0";
}

The video link below in the first half of the video shows what I currently have working in this code.

The last half of the video shows what I want.

I would change the circle graphic to a half circle...

https://youtu.be/781GzUulX1c

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I can't understand exactly what you want. It would be better if you shared the source file directly. I prepared an example, can you download and examine it?

we.tl/t-oflBkdma0o

I also convey that I cannot edit through your codes.

stage.enableMouseOver();

var root = this;
var knob_X = 454;
var knob_Y = 169;
var radius = 80;
var streakAngle;
var leye = true;


root.streakRotatorKnob.addEventListener("mouseover", mouseOverKnob.bind(this));

root.streakRotatorKnob.x = knob_X + radius * Math.cos(0);
root.streakRotatorKnob.y = knob_Y + radius * Math.sin(0);

function mouseOverKnob(evt)
{
    root.streakRotatorKnob.addEventListener("pressmove", moveF);
}


function moveF(evt) { 
    var rads = Math.atan2(stage.mouseY/stage.scaleY - knob_Y, stage.mouseX/stage.scaleX - knob_X);
    var atan_knob = Math.atan2(evt.currentTarget.y, evt.currentTarget.x);
    
    streakAngle = Math.round(((rads * 180 / Math.PI) * 100) / 100);
    
    if(streakAngle>=-90 && streakAngle<=90)
    {
        evt.currentTarget.x = knob_X + radius * Math.cos(rads);
        evt.currentTarget.y = knob_Y + radius * Math.sin(rads);
    }
    
    stage.update();
    //console.log("atan_knob: "+atan_knob);
    
    
    /*
    if (leye == true) {
        root.streakMainLeft.rotation = streakAngle + 90;
    } else if (reye == true) {
        root.streakMainRight.rotation = streakAngle + 90;
    }
    */
    console.log("streakAngle: " +streakAngle);
    //root.streakAngle.text = streakAngle + "\u00B0";
}
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!