Forum Topic: Get point in rotating mc (AS2)

(74 views • 5 replies)

This topic is 1 page long.

<< < > >>
Shouting

souled

Reply To Post Reply & Quote

Posted at: 11/4/09 05:10 PM

souled NEUTRAL LEVEL 14

Sign-Up: 09/18/06

Posts: 1,554

How do I get the point inside a rotating movie clip from a point outside of it? Let me show you:

Here I have a movie clip, square, and a point inside it, point.
SWF
The code is:

function onMouseDown()
{
	square.point._x = _xmouse - square._x;
	square.point._y = _ymouse - square._y;
}

And that is all well and good. But when the square rotates:
SWF
Code:

function onMouseDown()
{
	square.point._x = _xmouse - square._x;
	square.point._y = _ymouse - square._y;
}
function onEnterFrame()
{
	square._rotation++;
}

You see the problem. How would I deal with this?


None

LeechmasterB

Reply To Post Reply & Quote

Posted at: 11/4/09 05:14 PM

LeechmasterB EVIL LEVEL 16

Sign-Up: 04/01/05

Posts: 936

Check wikipedia on "polar coordinates"


None

knugen

Reply To Post Reply & Quote

Posted at: 11/4/09 05:44 PM

knugen LIGHT LEVEL 35

Sign-Up: 02/07/05

Posts: 4,654

It can be done manually with some trig, or with the help of localToGlobal() :)


None

K-Guare

Reply To Post Reply & Quote

Posted at: 11/4/09 06:12 PM

K-Guare FAB LEVEL 17

Sign-Up: 05/23/08

Posts: 2,413

At 11/4/09 05:44 PM, knugen wrote: It can be done manually with some trig, or with the help of localToGlobal() :)

Yep yep, local to global does it for you.
As you can see, k-guare slowly prepared a dandy little example while
knugen went and answered the question. :)

This code uses the same instance names as in yours, so
it's pretty much copy/pasteable. Not that I endorse that, though.

onEnterFrame = function() {
	square._rotation++;
}
onMouseDown = function() {
	var globalPoint:Object = {x:_xmouse, y:_ymouse};
	square.globalToLocal(globalPoint);
	square.point._x = globalPoint.x;
	square.point._y = globalPoint.y;
}

Sorry it took me so long,
localToGlobal in AS2 is a lot different than in AS3, had to figure it out. :/

i work alone. i wore cologne.

BBS Signature

Happy

souled

Reply To Post Reply & Quote

Posted at: 11/5/09 11:24 AM

souled NEUTRAL LEVEL 14

Sign-Up: 09/18/06

Posts: 1,554

Oh wow, thanks, didn't know about that.


None

liaaaam

Reply To Post Reply & Quote

Posted at: 11/5/09 11:33 AM

liaaaam NEUTRAL LEVEL 22

Sign-Up: 12/11/04

Posts: 14,536

At 11/4/09 06:12 PM, K-Guare wrote: Sorry it took me so long,
localToGlobal in AS2 is a lot different than in AS3, had to figure it out. :/

The only difference is that localToGlobal in AS3 returns a Point rather than altering the given Point, right? :P


All times are Eastern Standard Time (GMT -5) | Current Time: 02:47 AM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!