-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfade.lua2p
54 lines (43 loc) · 1.31 KB
/
fade.lua2p
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
local Flux = require("modules.flux.flux")
local Fade = {}
local f_duration = 1
local f_delay = 0.5
local f_color = {0, 0, 0, 0}
function Fade.fade_out(on_complete, duration, delay)
@@sassert(on_complete, type(on_complete) == "function")
@@sassert(duration, type(duration) == "number")
@@sassert(delay, type(delay) == "number")
local f = Flux.to(f_color, duration or f_duration, {[4] = 1})
:delay(delay or f_delay)
if on_complete then
f:oncomplete(on_complete)
end
end
function Fade.fade_in(on_complete, duration, delay)
@@sassert(on_complete, type(on_complete) == "function")
@@sassert(duration, type(duration) == "number")
@@sassert(delay, type(delay) == "number")
local f = Flux.to(f_color, duration or f_duration, {[4] = 0})
:delay(delay or f_delay)
if on_complete then
f:oncomplete(on_complete)
end
end
function Fade.set_alpha(a)
@@assert(type(a) == "number")
f_color[4] = a
end
function Fade.draw()
local w, h = love.graphics.getDimensions()
love.graphics.setColor(Fade.getColor())
love.graphics.rectangle("fill", 0, 0, w, h)
end
function Fade.set_color(color)
@@assert(type(color) == "table")
f_color[1] = color[1] or f_color[1]
f_color[2] = color[2] or f_color[2]
f_color[3] = color[3] or f_color[3]
f_color[4] = color[4] or f_color[4]
end
function Fade.getColor() return f_color end
return Fade