Rotation with trig
/**
* Copyright terravilor ( http://wonderfl.net/user/terravilor )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/xVhO
*/
package {
import flash.events.Event;
import flash.display.Sprite;
public class FlashTest extends Sprite {
private var arrow:Arrow;
public function FlashTest() {
arrow = new Arrow();
arrow.x = (stage.stageWidth / 2);
arrow.y = (stage.stageHeight / 2);
addChild(arrow);
addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
protected function onEnterFrame(event:Event):void {
var dy:Number = mouseY - arrow.y;
var dx:Number = mouseX - arrow.x;
var radians:Number = Math.atan2(dy, dx);
//var radians:Number = Math.atan(dy / dx); <- vai dar errado pelo fato do flash não entender o quadrante do mouse
var degrees:Number = radians * 180 / Math.PI;
arrow.rotation = degrees;
}
}
}
//arrow
import flash.display.Sprite;
class Arrow extends Sprite {
public function Arrow() {
init();
}
public function init():void {
graphics.lineStyle(1,0,1);
graphics.beginFill(0xff0000);
graphics.moveTo(-50,-25);
graphics.lineTo(0,-25);
graphics.lineTo(0,-50);
graphics.lineTo(50,0);
graphics.lineTo(0,50);
graphics.lineTo(0,25);
graphics.lineTo(-50,25);
graphics.lineTo(-50,-25);
graphics.endFill();
}
}