86 lines
2.2 KiB
Lua
86 lines
2.2 KiB
Lua
|
|
||
|
local transitionEnterAnimation;
|
||
|
local transitionLeaveAnimation;
|
||
|
|
||
|
local resx, resy = game.GetResolution()
|
||
|
|
||
|
local timer = 0;
|
||
|
local outTimer = 0;
|
||
|
|
||
|
local wasEnterSfxPlayed = false;
|
||
|
local wasLeaveSfxPlayed = false;
|
||
|
|
||
|
game.LoadSkinSample('transition_screen/transition_enter.wav');
|
||
|
game.LoadSkinSample('transition_screen/transition_leave.wav');
|
||
|
|
||
|
function loadAnimations()
|
||
|
transitionEnterAnimation = gfx.LoadSkinAnimation('transition/transition_frames/enter', 1/60, 1, false);
|
||
|
transitionLeaveAnimation = gfx.LoadSkinAnimation('transition/transition_frames/leave', 1/60, 1, false);
|
||
|
end
|
||
|
|
||
|
function render(deltaTime)
|
||
|
if not transitionEnterAnimation then
|
||
|
loadAnimations()
|
||
|
end
|
||
|
|
||
|
if not wasEnterSfxPlayed then
|
||
|
game.PlaySample('transition_screen/transition_enter.wav');
|
||
|
wasEnterSfxPlayed = true;
|
||
|
end
|
||
|
|
||
|
BREAKPOINT_INVISIBLE = 0.27;
|
||
|
BREAKPOINT_VISIBLE = BREAKPOINT_INVISIBLE + 0.05;
|
||
|
|
||
|
|
||
|
if timer < BREAKPOINT_INVISIBLE then
|
||
|
gfx.GlobalAlpha(0);
|
||
|
elseif (timer >= BREAKPOINT_INVISIBLE and timer < BREAKPOINT_VISIBLE) then
|
||
|
gfx.GlobalAlpha((timer-BREAKPOINT_INVISIBLE) * (1/(BREAKPOINT_VISIBLE-BREAKPOINT_INVISIBLE)));
|
||
|
else
|
||
|
gfx.GlobalAlpha(1);
|
||
|
end
|
||
|
|
||
|
gfx.ImageRect(0, 0, resx, resy, transitionEnterAnimation, 1, 0);
|
||
|
gfx.TickAnimation(transitionEnterAnimation, deltaTime);
|
||
|
gfx.GlobalAlpha(1);
|
||
|
|
||
|
-- debug
|
||
|
-- gfx.Text('DELTA: ' .. deltaTime .. ' // TIMER: ' .. timer .. ' // TIMER_OUT: ' .. outTimer, 255,255);
|
||
|
timer = timer + (deltaTime / 3);
|
||
|
|
||
|
if timer >= 1 then return true end;
|
||
|
end
|
||
|
|
||
|
function render_out(deltaTime)
|
||
|
if not wasLeaveSfxPlayed then
|
||
|
game.PlaySample('transition_screen/transition_leave.wav');
|
||
|
wasLeaveSfxPlayed = true;
|
||
|
end
|
||
|
|
||
|
gfx.ImageRect(0, 0, resx, resy, transitionLeaveAnimation, 1, 0);
|
||
|
gfx.TickAnimation(transitionLeaveAnimation, deltaTime);
|
||
|
|
||
|
outTimer = outTimer + (1/60) / 0.5
|
||
|
|
||
|
if outTimer >= 1 then
|
||
|
return true;
|
||
|
end
|
||
|
|
||
|
end
|
||
|
|
||
|
function sign(x)
|
||
|
return x>0 and 1 or x<0 and -1 or 0
|
||
|
end
|
||
|
|
||
|
|
||
|
function reset()
|
||
|
resx, resy = game.GetResolution();
|
||
|
timer = 0;
|
||
|
outTimer = 0;
|
||
|
|
||
|
transitionEnterAnimation = nil;
|
||
|
transitionLeaveAnimation = nil;
|
||
|
|
||
|
wasEnterSfxPlayed = false;
|
||
|
wasLeaveSfxPlayed = false;
|
||
|
end
|