-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfade.nut
112 lines (92 loc) · 2.33 KB
/
fade.nut
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
class FadeInObject
{
fade_time=500;
fade_trigger=null;
_object=null;
_last_switch=0;
_in_fade=false;
_trigger_load=false;
constructor(object) {
_object = object;
_object.alpha=0;
fe.add_transition_callback(this, "on_transition");
fe.add_ticks_callback(this, "on_tick");
}
function on_transition(ttype, var, ttime)
{
if (ttype == fade_trigger)
{
if (_in_fade) {
_in_fade=false;
}
_trigger_load=true;
}
return false;
}
function on_tick(ttime) {
if (_trigger_load) {
_in_fade=true;
_last_switch=ttime;
_object.alpha=0;
_trigger_load=false;
}
if (_in_fade) {
local new_alpha = 255 * (ttime-_last_switch) / fade_time;
if (new_alpha > 255) {
_in_fade=false;
} else {
_object.alpha = new_alpha;
}
}
}
}
class FadeOutObject {
fade_time = 500;
fade_trigger = null;
_object = null;
_last_switch = 0;
_do_fade = false;
_trigger_load = false;
constructor(object) {
_object = object;
_object.alpha = 0;
fe.add_transition_callback(this, "on_transition");
fe.add_ticks_callback(this, "on_tick");
}
function on_transition(ttype, var, ttime) {
if (ttype == fade_trigger)
{
if (_do_fade) {
_do_fade = false;
}
_trigger_load = true;
}
return false;
}
function on_tick(ttime) {
if (_trigger_load) {
_do_fade = true;
_last_switch = ttime;
_object.alpha = 255;
_trigger_load = false;
}
if (_do_fade) {
local new_alpha = 255 * (ttime - _last_switch) / fade_time;
if (new_alpha > 255) {
_do_fade = false;
new_alpha = 255;
}
_object.alpha = 255 - new_alpha;
}
}
}
class FadeDelayedVideo extends FadeArt {
start_delay = 1000;
function on_tick(ttime) {
base.on_tick(ttime);
if ((ttime - _last_switch) > start_delay) {
_back.video_playing = true;
_front.video_playing = false;
}
}
}