2021-07-25 20:10:06 +02:00
|
|
|
|
2022-03-04 04:06:19 +01:00
|
|
|
local common = require('common.util');
|
|
|
|
local Sound = require("common.sound")
|
2021-11-21 16:34:12 +01:00
|
|
|
|
2021-07-25 20:10:06 +02:00
|
|
|
local transitionEnterAnimation;
|
|
|
|
local transitionLeaveAnimation;
|
|
|
|
|
2021-12-02 03:41:12 +01:00
|
|
|
local backgroundImage = gfx.CreateSkinImage("bg_pattern.png", gfx.IMAGE_REPEATX | gfx.IMAGE_REPEATY)
|
|
|
|
|
|
|
|
-- Window variables
|
|
|
|
local resX, resY = game.GetResolution()
|
|
|
|
|
|
|
|
-- Aspect Ratios
|
|
|
|
local landscapeWidescreenRatio = 16 / 9
|
|
|
|
local landscapeStandardRatio = 4 / 3
|
|
|
|
local portraitWidescreenRatio = 9 / 16
|
|
|
|
|
|
|
|
-- Portrait sizes
|
|
|
|
local fullX = portraitWidescreenRatio * resY
|
|
|
|
local fullY = resY
|
2021-07-25 20:10:06 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2021-12-02 03:41:12 +01:00
|
|
|
function drawBackground()
|
|
|
|
gfx.BeginPath()
|
|
|
|
local bgImageWidth, bgImageHeight = gfx.ImageSize(backgroundImage)
|
|
|
|
gfx.Rect(0, 0, resX, resY)
|
|
|
|
gfx.FillPaint(gfx.ImagePattern(0, 0, bgImageWidth, bgImageHeight, 0, backgroundImage, 0.2))
|
|
|
|
gfx.Fill()
|
|
|
|
end
|
|
|
|
|
2021-07-25 20:10:06 +02:00
|
|
|
function render(deltaTime)
|
2021-12-02 03:41:12 +01:00
|
|
|
local x_offset = (resX - fullX) / 2
|
|
|
|
local y_offset = 0
|
|
|
|
|
|
|
|
gfx.BeginPath()
|
|
|
|
|
2022-03-04 04:06:19 +01:00
|
|
|
Sound.stopMusic();
|
2021-11-21 16:34:12 +01:00
|
|
|
|
2021-07-25 20:10:06 +02:00
|
|
|
if not transitionEnterAnimation then
|
|
|
|
loadAnimations()
|
|
|
|
end
|
|
|
|
|
2021-07-25 20:49:53 +02:00
|
|
|
local enterAnimTickRes = gfx.TickAnimation(transitionEnterAnimation, deltaTime);
|
2021-07-25 20:10:06 +02:00
|
|
|
|
2021-07-25 20:49:53 +02:00
|
|
|
if enterAnimTickRes == 0 then
|
2021-07-25 20:10:06 +02:00
|
|
|
gfx.GlobalAlpha(0);
|
|
|
|
else
|
2021-07-25 20:49:53 +02:00
|
|
|
if not wasEnterSfxPlayed then
|
|
|
|
game.PlaySample('transition_screen/transition_enter.wav');
|
|
|
|
wasEnterSfxPlayed = true;
|
|
|
|
end
|
2021-11-20 22:01:08 +01:00
|
|
|
gfx.BeginPath();
|
2021-12-02 03:41:12 +01:00
|
|
|
gfx.ImageRect(x_offset, y_offset, fullX, fullY, transitionEnterAnimation, 1, 0);
|
2021-07-25 20:10:06 +02:00
|
|
|
gfx.GlobalAlpha(1);
|
2021-07-25 20:49:53 +02:00
|
|
|
|
|
|
|
-- debug
|
2022-02-17 18:06:25 +01:00
|
|
|
if game.GetSkinSetting('debug_showInformation') then
|
|
|
|
gfx.Text('DELTA: ' .. deltaTime .. ' // TIMER: ' .. timer .. ' // TIMER_OUT: ' .. outTimer, 255,255);
|
|
|
|
end
|
2021-07-25 20:49:53 +02:00
|
|
|
timer = timer + (deltaTime / 3);
|
2021-07-25 20:10:06 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
if timer >= 1 then return true end;
|
|
|
|
end
|
|
|
|
|
|
|
|
function render_out(deltaTime)
|
2021-07-25 20:49:53 +02:00
|
|
|
local leaveAnimeTickRes = gfx.TickAnimation(transitionLeaveAnimation, deltaTime);
|
2021-12-02 03:41:12 +01:00
|
|
|
local x_offset = (resX - fullX) / 2
|
|
|
|
local y_offset = 0
|
|
|
|
|
|
|
|
gfx.BeginPath()
|
2021-07-25 20:49:53 +02:00
|
|
|
|
|
|
|
if leaveAnimeTickRes == 0 then
|
2021-11-20 22:01:08 +01:00
|
|
|
gfx.BeginPath();
|
2021-12-02 03:41:12 +01:00
|
|
|
gfx.ImageRect(x_offset, y_offset, fullX, fullY, transitionEnterAnimation, 1, 0);
|
2021-07-25 20:49:53 +02:00
|
|
|
else
|
|
|
|
if not wasLeaveSfxPlayed then
|
|
|
|
game.PlaySample('transition_screen/transition_leave.wav');
|
|
|
|
wasLeaveSfxPlayed = true;
|
|
|
|
end
|
2021-07-25 20:10:06 +02:00
|
|
|
|
2021-11-20 22:01:08 +01:00
|
|
|
gfx.BeginPath();
|
2021-12-02 03:41:12 +01:00
|
|
|
gfx.ImageRect(x_offset, y_offset, fullX, fullY, transitionLeaveAnimation, 1, 0);
|
2021-07-25 20:49:53 +02:00
|
|
|
outTimer = outTimer + (1/60) / 0.5
|
|
|
|
end
|
2021-07-25 20:10:06 +02:00
|
|
|
|
|
|
|
|
|
|
|
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()
|
2021-12-02 03:41:12 +01:00
|
|
|
resX, resY = game.GetResolution();
|
|
|
|
fullX = portraitWidescreenRatio * resY
|
|
|
|
fullY = resY
|
2021-07-25 20:10:06 +02:00
|
|
|
timer = 0;
|
|
|
|
outTimer = 0;
|
|
|
|
|
|
|
|
transitionEnterAnimation = nil;
|
|
|
|
transitionLeaveAnimation = nil;
|
|
|
|
|
|
|
|
wasEnterSfxPlayed = false;
|
|
|
|
wasLeaveSfxPlayed = false;
|
|
|
|
end
|