PDA

View Full Version : Rotating a clip


FatedToAsk
08-24-2009, 04:32 AM
package fated.mouse{
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.display.Stage;

public class ClipRotate{
private var _clip:MovieClip;
private var _stage:Stage;
public function ClipRotate(clip:MovieClip, stage:Stage) {
_clip=clip;
_stage=stage;
_stage.addEventListener(MouseEvent.MOUSE_MOVE, rotate);
}
private function rotate(event:MouseEvent) {
var X:int = _clip.mouseX;
var Y:int = _clip.mouseY;
var angle:Number = Math.atan2(Y,X)/(Math.PI/180);
trace("X: " + X + " Y: " + Y + " Angle: " + angle);
_clip.rotation=angle;
}
}
}

It appears that _clip.mouseX/Y seem to change quite dramatically between pixels, and seems to almost go in the polar opposites. (_clip.mouseX will be at 100 more example, but after moving just a smidgen, a pixel or two than it jumps all the way to around -100)

What is the problem with this code that my friend and I are experiencing? Any suggestions?

henke37
08-24-2009, 06:37 AM
Maybe you shouldn't get the mouse coordinates from the coordinate system that is rotating?

FatedToAsk
08-24-2009, 10:57 AM
Maybe you shouldn't get the mouse coordinates from the coordinate system that is rotating?

That shouldn't matter if you register the point being inside the middle of the movie clip. All is fine when disable the actual rotating part, I can put the mouse in the middle of the shape and it traces back to being 0, 0. It rotates at the point in the middle to, but after it rotates it gets funky.

henke37
08-24-2009, 02:44 PM
My point is that it's not a stable system. Rotating the MC changes the coordinate system, leading to new values for the mouse position, even if it's not moved.
Basicaly, if you rotate N degrees around the registration point, the mouse position has to rotate -N degrees around the registration point.
Just grab the mouse position from the container instead of the containee.