1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
var
temp:
int
;
stage.addEventListener(
"mouseMove"
,rota);
//为舞台添加一个监听
var
tempNumsin:
Number
=
0
;
var
tempNumcos:
Number
=
0
;
var
ganX:
Number
=
0
;
var
ganY:
Number
=
0
;
function
rota(event:Event):
void
{
//计算出dx,和dy
var
dx:
Number
= a1.x - stage.mouseX;
var
dy:
Number
= a1.y - stage.mouseY;
//计算出角度
var
angle:
Number
= Math.atan2(dx,dy);
a1.rotation = -angle *
180
/ Math.PI;
//注意sin里面的值不能为数必须转换为角度
tempNumsin = Math.abs(Math.sin(a1.rotation*Math.PI/
180
));
tempNumcos = Math.abs(Math.cos(a1.rotation*Math.PI/
180
));
if
(a1.rotation <=
0
) {
ganX = a1.x - tempNumsin *
390
;
ganY = a1.y - tempNumcos*
390
;
}
else
{
ganX = a1.x + tempNumsin *
390
;
ganY = a1.y - tempNumcos *
390
;
}
}
|