View Full Version : arrow rotation
charmander
July 18th, 2005, 03:36 AM
Hi every one…..
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
I attached a file that's consisted of three objects….
<o:p></o:p>
1-the blue square, called "mineobject"….it's the object I control on it (by keyboard)
<o:p></o:p>
2-the red circle, called "otherobject"…..it's the object sliding to the left direction, I haven't control on it
<o:p></o:p>
3-the green arrow, it's movement binding with the moving of the blue square that I can control on it….
<o:p></o:p>
The desire :
<o:p></o:p>
I want the arrow get rotation to refer to the red circle…. There are too many files talking about this..but when we control on object by mouse only…in this we control the referring operate without mouse……………
<o:p></o:p>
Can any one help me……………………
TheCanadian
July 18th, 2005, 04:53 AM
I can't really understand what you are saying but I think you are asking how to make the green arrow rotate towards the red circle. If so, this is how you do it (put the code on the green arrow):
onClipEvent (enterFrame) {
radians = Math.atan2(_root.otherobject._y-this._y, _root.otherobject._x-this._x);
degrees = Math.round((radians*180/Math.PI));
this._rotation = degrees+90;
}
Explanation time. The first line is the On handler for the movie clip. It tells the code to excecute every time the movie clip enters the frame. Now this is the math part. 'radians' is a variable we set up so that we can call upon this equation later. The Math.atan2 method computes the arctangent of the parameters within the bracket. Since we are using the Math.atan2 method, the parameters are a y,x coordinate. In this case we find the difference between the positions of the otherobject and the regestration point of the current movie clip. Flash then uses the arctangent ratio to calculate measure of the angle in radians. 'degrees' is a variable we set up so that we can call upon it later. The Math.round method rounds the numbers within the brackets up or down to the nearest whole number. The equation within these brackets is what converts radians into degrees since flash uses degrees to measure the rotation of objects. It multiples the radians (which flash calculated earlier) by 180 then divides them by Math.PI which is a constant representing the value of pi. Know you have degrees. This line is the one that actually rotates the movieclip the number of degrees specified by the variable 'degrees'.
Such a long explanation for such a short bit of code. If this is not what you wanted then I guess I wasted everyones time. But just ask again.
charmander
July 18th, 2005, 07:40 AM
don't say that....the new code exactlly what i need.....thank you "the canadian"...
but tell me....are you really don't understand me!!
NiñoScript
July 18th, 2005, 11:15 AM
i rally didnt get you, i didnt even know if the problem was solved, but heres a fla and a swf if thats what you mean...
charmander
July 18th, 2005, 11:42 AM
the problem solved by "the canadian"in his reply...and your file is diffrent off the desire...download the attacment in the first reply and then add the code in the secound reply (in the arrow) and you will get it....but thank you for you interest...
TheCanadian
July 18th, 2005, 09:00 PM
Glad I could help.
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.