From 31dc0e443efc0aae48e11a0d98e699dbed5c7dcf Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Wed, 10 Feb 2021 12:11:27 -0500 Subject: Added fade out around map change Also moved script system first in the loop so that the camera can catch up before rendering. Also added a map change from map 2 back to map 1. --- res/scripts/common.lua | 25 +++++++++++++++++++++++++ res/scripts/map1_off_right.lua | 8 +------- res/scripts/map2_off_left.lua | 3 +++ 3 files changed, 29 insertions(+), 7 deletions(-) create mode 100644 res/scripts/map2_off_left.lua (limited to 'res/scripts') diff --git a/res/scripts/common.lua b/res/scripts/common.lua index e7af1cf..f43b2e0 100644 --- a/res/scripts/common.lua +++ b/res/scripts/common.lua @@ -38,3 +38,28 @@ end function StopSound(soundId) mixer():stopChannel(soundId) end + +function FadeToBlack(length) + local progress = 0.0 + while progress < length do + progress = progress + coroutine.yield() + setFadeoutProgress(progress / length) + end + setFadeoutProgress(1.0) +end + +function RemoveFadeout(length) + local progress = length + while progress > 0 do + progress = progress - coroutine.yield() + setFadeoutProgress(progress / length) + end + setFadeoutProgress(0.0) +end + +function ChangeMap(map, warp) + FadeToBlack(150) + loadMap("../res/maps/" .. map .. ".tmx", warp) + coroutine.yield() + RemoveFadeout(150) +end diff --git a/res/scripts/map1_off_right.lua b/res/scripts/map1_off_right.lua index 026c32e..7dd0113 100644 --- a/res/scripts/map1_off_right.lua +++ b/res/scripts/map1_off_right.lua @@ -1,9 +1,3 @@ function map1_off_right() - -- Because this script gets triggered within the CharacterSystem's tick method, - -- if we immediately cleared out the entities from the old map, we might end up - -- returning there and processing stale data. This yield here ensures that we - -- are no longer in the CharacterSystem, because processing gets picked back up - -- in the ScriptSystem. - coroutine.yield() - loadMap("../res/maps/map2.tmx", "fromLeft") + ChangeMap("map2", "fromLeft") end diff --git a/res/scripts/map2_off_left.lua b/res/scripts/map2_off_left.lua new file mode 100644 index 0000000..d4d9ce4 --- /dev/null +++ b/res/scripts/map2_off_left.lua @@ -0,0 +1,3 @@ +function map2_off_left() + ChangeMap("map1", "fromRight") +end -- cgit 1.4.1