|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
Hi guys.
I have a graphic (arrow) which spins round on the same spot pointing to wherever the mouse go's. Instead of the arrow pointing to every single angle (360 degrees) I want it to either point up, down, left or right. I think it might need rounding up/down some how to the nearest 90 degrees? Here's my code that I use just to spin the arrow graphic. onClipEvent (load) { _x += Number(2); friction = .7; speedratio = .2; xspeed = 0; yspeed = 0; xgoal = this._x; ygoal = this._y; } onClipEvent (enterFrame) { // figure out our slope var slope = (_root._ymouse-_y)/(_root._xmouse-_x); // get it in usable form... var radians = Math.atan(slope); var theta = (radians*180)/Math.PI; theta += (_root._xmouse<_x) ? 180 : 0; // set the rotation _rotation = theta; } Can anyone help?? Much appreciated.
__________________
Captain Planet. Last edited by Captain Planet : January 8th, 2004 at 07:52 AM. |
|
#2
|
|||
|
|||
|
Hi, this should do it:
Code:
onClipEvent (enterFrame) {
var slope = (_root._ymouse-_y)/(_root._xmouse-_x);
var radians = Math.atan(slope);
var theta = (radians*180)/Math.PI;
theta += (_root._xmouse<_x) ? 180 : 0;
if(theta == 0 || theta == 90 || theta == 180 || theata == 270)
{
// set the rotation
_rotation = theta;
}
}
You can use Math.floor(theta) or Math.ceil(theta) if you need to round it up/down. I wrote the above here so I havent tested it. Not sure if theta would == 0 || 360..think its zero though. |
|
#3
|
||||
|
||||
|
It stopped working Tann, obviously it never got into the if statement. I was thinking, the arrow is pointing to 4 different images. Could I reference it to them and say something like:
if mouseOver image1 begin rotate arrow x degrees end If so how???? |
|
#4
|
|||
|
|||
|
Hi, yer that would definately work. The easiest and quickest way would be to make each of the four images into a button. Just manually do it. Then for each button use:
on(rollOver) { myArrow._rotation = 0; myArrow._rotation = 90; myArrow._rotation = 180; myArrow._rotation = 270; } Obviously you only use one of those four statements for each button, which one depends on the angle your arrow starts in i.e. up, left etc... If you have dynamically loaded the images then you should definately look into assigning mouse events that way otherwise dont worry about it. |
|
#5
|
||||
|
||||
|
I'll give that a shot now. Cheers tan.
|
![]() |
| Viewing: Dev Shed Forums > Web Design > Flash Help > round up/down to nearest 90 degrees. |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|