Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

164
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda