0

Using Adobe Animate HTML5 Canvas which employs Create.js/Easel.js.

I have the following code which drags an object around a circle.

Works Ok, but the object should only be moveable when the cursor is over the object; object being streakRotatorKnob.

var knob_X = 454;
var knob_Y = 175;
var radius = 80;

root.streakRotatorKnob.addEventListener("pressmove",moveF.bind(this));

function moveF(e){ 
var rads = Math.atan2(stage.mouseY-knob_Y,stage.mouseX-knob_X);
e.currentTarget.x = knob_X + radius * Math.cos(rads);
e.currentTarget.y = knob_Y + radius * Math.sin(rads);
stage.update();
}

I have tried the following but it's not working at all with the if statement:

var knob_X = 454;
var knob_Y = 175;
var radius = 80;

root.streakRotatorKnob.addEventListener("pressmove",moveF.bind(this));

function moveF(e){
    if(stage.mouseY == root.streakRotatorKnob.y && stage.mouseX == root.streakRotatorKnob.x){
var rads = Math.atan2(stage.mouseY-knob_Y,stage.mouseX-knob_X);
e.currentTarget.x = knob_X + radius * Math.cos(rads);
e.currentTarget.y = knob_Y + radius * Math.sin(rads);
stage.update();
    }
}
2

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.