Hello again. I'd like to draw a line from pointA to the mouse position, and trace along that line and return the x,y position every 5 pixels.
If I could get any help on this it would be most appreciated.
Thanks!
Brendan
Printable View
Hello again. I'd like to draw a line from pointA to the mouse position, and trace along that line and return the x,y position every 5 pixels.
If I could get any help on this it would be most appreciated.
Thanks!
Brendan
Can you explain this a bit better? Maybe an illustration? Maybe an example of code you've tried? Help me help you. :/
Well, it looks like you need to create something like a measuring tape, don't you?
You'll have to use Point.distance() function to calculate the distance between 2 points.
This method is basically a Pythagorean theorem.
then use:
graphics.lineStyle();
graphics.lineTo();
and
graphics.clear(); to remove the line that was created a frame before
ok this is how you might do it in AS1. maybe some kind soul could translate it to AS2/3;
1. create a blank mc and call it "lineMc" and place it on the stage
2. lets assume pointA is an object containing the x/y point that you have
3. code goes on the main timeline
This is off the top of my head so it may not be 100% kosher syntax wiseCode://
// Move the lineMc to the point
lineMc._x = lineA.x;
lineMc._y = lineA.y
//
// Calculate the angle to the mouse
var d = { x: _xmouse - lineMc._x, y: _ymouse - lineMc._y };
lineMc._rotation = ((Math.atan2(d.y, d.x)/Math.PI)*180);
//
// Get position of mouse relative to the lineMc
var m = { x: _xmouse, y: _ymouse };
lineMc.globalToLocal(m);
//
// Now count every 5 pixels along the x-axis of the lineMc
// until you are past the position of the mouse(m);
for(var x=0; x < m.x; x += 5) {
// x will now count off 5 pixel steps until it reaches (or exceeds)
// the mouse position.
// if you want the position relative to the main stage then you do this;
var s = { y: 0, x: x };
lineMc.localToGlobal(s);
//
// Now s should contains the (x,y) position of the current step
// relative to the main stage
}
stop ();