Question

I have two draggable objects, and when your drag one them it generates a line based off where your mouse is, and the line is anchored to the other object. What Id like this code to do, is generate the line at the rear of the symbol

I got this

enter image description here

but I need this

enter image description here

       if ((mouseX-targetPointX<0 && mouseY-targetPointY>0) || (mouseX-targetPointX>=0 && mouseY-targetPointY<=0)) {
        line.moveTo(mouseX-offset,mouseY-offset);
        line.curveTo(mouseX-offset,targetPointY-offset,targetPointX-offset,targetPointY-offset);
        line.lineTo(targetPointX+offset,targetPointY+offset);
        line.curveTo(mouseX+offset,targetPointY+offset,mouseX+offset,mouseY+offset);
    } else {
        line.moveTo(mouseX-offset,mouseY+offset);
        line.curveTo(mouseX-offset,targetPointY+offset,targetPointX-offset,targetPointY+offset);
        line.lineTo(targetPointX+offset,targetPointY-offset);
        line.curveTo(mouseX+offset,targetPointY-offset,mouseX+offset,mouseY-offset);
    }
    line.endFill();
};
Was it helpful?

Solution

Instead of using the mouse position as reference to draw your curve, you can use a custom Point object with the coordinates from where you want the curve to start from.

moveTo(myPoint.x, myPoint.y);

You can create any Point you want, for example at (50,200) using the relative coordinates from your Sprite, and then find the global coordinates using localToGlobal.

var globalPoint:Point = mySprite.localToGlobal(new Point(50,200));
trace(globalPoint.x,globalPoint.y);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top