-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSpiningAnimation.as
77 lines (62 loc) · 1.68 KB
/
SpiningAnimation.as
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package {
import flash.display.MovieClip;
import flash.events.Event;
public class SpiningAnimation extends MovieClip {
static const EVENT_SPEED_UP:String = "Speed_Up";
private var SPIN_SPEED:Number;
private const SPIN_SPEED_HIGH:Number = 55;
private var vr:Number; //旋转速度
private var direction:Boolean; //顺逆时针
public function SpiningAnimation() {
// constructor code
SPIN_SPEED = Math.random() * 5;
vr = SPIN_SPEED;
direction = Math.random()>0.5;
addEventListener(Event.ADDED_TO_STAGE, onAddToStage);
}
public function onAddToStage(event:Event):void
{
removeEventListener(Event.ADDED_TO_STAGE, onAddToStage);
addEventListener(Event.REMOVED_FROM_STAGE, onRemoveFromStage);
addEventListener(Event.ENTER_FRAME, onEnterFrame);
//stage.addEventListener(EVENT_SPEED_UP, onSpeedUp);
stage.addEventListener(Bar.click_event, onSpeedUp);
}
public function set_direction(d:Boolean):void
{
direction = d;
}
public function onEnterFrame(event:Event):void
{
if (direction)
{
rotation += vr;
}
else
{
rotation -= vr;
}
if (vr > SPIN_SPEED)
{
//缓动减速
vr -= (vr - SPIN_SPEED) * 0.13;
if (vr - 0.2 <= SPIN_SPEED)
{
vr = SPIN_SPEED;
}
}
}
public function onSpeedUp(event:Event):void
{
//trace("ss");
vr = SPIN_SPEED_HIGH;
}
public function onRemoveFromStage(event:Event)
{
removeEventListener(Event.REMOVED_FROM_STAGE, onRemoveFromStage);
removeEventListener(Event.ENTER_FRAME, onEnterFrame);
//stage.removeEventListener(EVENT_SPEED_UP, onSpeedUp);
stage.removeEventListener(Bar.click_event, onSpeedUp);
}
}
}