From 535ec4f369cfd5b8f360426f96d37e2e854cab08 Mon Sep 17 00:00:00 2001 From: FajsiEx Date: Sun, 25 Jul 2021 20:49:53 +0200 Subject: [PATCH] / fix stutters in transition animations & + add fade in transition after the idol animation is loaded --- scripts/titlescreen.lua | 16 ++++++++++++-- scripts/transition.lua | 48 ++++++++++++++++++++--------------------- 2 files changed, 37 insertions(+), 27 deletions(-) diff --git a/scripts/titlescreen.lua b/scripts/titlescreen.lua index eb3ebd1..48d6a85 100644 --- a/scripts/titlescreen.lua +++ b/scripts/titlescreen.lua @@ -39,6 +39,8 @@ local selectorLegendSelectLabel = gfx.CreateLabel('START', 20, 0); local scrollTransitionScale = 1; -- Goes from 0 to 1 when transition is happening, sits at 1 when it's not. local buttonsMovementScale = 0; -- Basically same as `scrollTransitionScale` but with a +/- sign for the scroll direction and goes from 1 to 0 +local idolAnimTransitionScale = 0; + local oldCursorIndex = 3; local scrollingUp = false; local playedBgm = false; @@ -240,8 +242,18 @@ render = function(deltaTime) -- Draw background gfx.ImageRect(0, 0, resx, resy, bgImage, 1, 0); - gfx.ImageRect(0, 0, resx, resy, idolAnimation, 1, 0); - gfx.TickAnimation(idolAnimation, deltaTime); + local idolAnimTickRes = gfx.TickAnimation(idolAnimation, deltaTime); + if idolAnimTickRes == 1 then + gfx.GlobalAlpha(idolAnimTransitionScale); + + idolAnimTransitionScale = idolAnimTransitionScale + 1/60; + if (idolAnimTransitionScale > 1) then + idolAnimTransitionScale = 1; + end + + gfx.ImageRect(0, 0, resx, resy, idolAnimation, 1, 0); + gfx.GlobalAlpha(1); + end -- Draw selector background gfx.ImageRect(0, (resy/2) - 280/2, 1079, 280, selectorBgImage, 1, 0); diff --git a/scripts/transition.lua b/scripts/transition.lua index 505a111..de4e3ba 100644 --- a/scripts/transition.lua +++ b/scripts/transition.lua @@ -23,44 +23,42 @@ function render(deltaTime) 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; - + local enterAnimTickRes = gfx.TickAnimation(transitionEnterAnimation, deltaTime); - if timer < BREAKPOINT_INVISIBLE then + if enterAnimTickRes == 0 then gfx.GlobalAlpha(0); - elseif (timer >= BREAKPOINT_INVISIBLE and timer < BREAKPOINT_VISIBLE) then - gfx.GlobalAlpha((timer-BREAKPOINT_INVISIBLE) * (1/(BREAKPOINT_VISIBLE-BREAKPOINT_INVISIBLE))); else + if not wasEnterSfxPlayed then + game.PlaySample('transition_screen/transition_enter.wav'); + wasEnterSfxPlayed = true; + end + gfx.ImageRect(0, 0, resx, resy, transitionEnterAnimation, 1, 0); gfx.GlobalAlpha(1); + + -- debug + -- gfx.Text('DELTA: ' .. deltaTime .. ' // TIMER: ' .. timer .. ' // TIMER_OUT: ' .. outTimer, 255,255); + timer = timer + (deltaTime / 3); 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; + local leaveAnimeTickRes = gfx.TickAnimation(transitionLeaveAnimation, deltaTime); + + if leaveAnimeTickRes == 0 then + gfx.ImageRect(0, 0, resx, resy, transitionEnterAnimation, 1, 0); + else + if not wasLeaveSfxPlayed then + game.PlaySample('transition_screen/transition_leave.wav'); + wasLeaveSfxPlayed = true; + end + + gfx.ImageRect(0, 0, resx, resy, transitionLeaveAnimation, 1, 0); + outTimer = outTimer + (1/60) / 0.5 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;