package
{
import flash.display.Sprite;
import flash.events.*;
public class Diaoyong extends Sprite
{
var arrow:Arrow=new Arrow();
public function Diaoyong()
{
// constructor code
init();
}
public function init()
{
arrow = new Arrow();
addChild(arrow);
arrow.x = stage.stageWidth / 2;
arrow.y = stage.stageHeight / 2;
addEventListener(Event.ENTER_FRAME,djhs);
}
public function djhs(e)
{
var dx:Number = mouseX - arrow.x;
var dy:Number = mouseY - arrow.y;
var radians:Number = Math.atan2(dy,dx);
trace(radians);
arrow.rotation = radians * 180 / Math.PI;
}
}
返回
{
import flash.display.Sprite;
import flash.events.*;
public class Diaoyong extends Sprite
{
var arrow:Arrow=new Arrow();
public function Diaoyong()
{
// constructor code
init();
}
public function init()
{
arrow = new Arrow();
addChild(arrow);
arrow.x = stage.stageWidth / 2;
arrow.y = stage.stageHeight / 2;
addEventListener(Event.ENTER_FRAME,djhs);
}
public function djhs(e)
{
var dx:Number = mouseX - arrow.x;
var dy:Number = mouseY - arrow.y;
var radians:Number = Math.atan2(dy,dx);
trace(radians);
arrow.rotation = radians * 180 / Math.PI;
}
}
}
-----------------
atan2 | () | 方法 |
public static function atan2(y:Number, x:Number):Number
语言版本: | ActionScript 3.0 |
运行时版本: | AIR 1.0 Flash Player 9, Flash Lite 4 |
以弧度为单位计算并返回点 y
/x
的角度,该角度从圆的 x 轴(其中,0,0 表示圆心)沿逆时针方向测量。返回值介于正 pi 和负 pi 之间。请注意,atan2 的第一个参数始终是 y 坐标。
参数
y:Number — 该点的 y 坐标。 | |
x:Number — 该点的 x 坐标。 |
Number — 一个数字。 |