Screen fader on level transition

This commit is contained in:
Marco 2025-02-24 13:47:38 +01:00
commit 959701be08
6 changed files with 80 additions and 8 deletions

View file

@ -32,6 +32,7 @@ script = ExtResource("1_na4uq")
BossName = "Rumia"
Phases = Array[Resource]([ExtResource("2_1rhf6"), ExtResource("3_j7lbl"), ExtResource("2_eyxw4"), ExtResource("2_p8j4e")])
BossHudPrefab = ExtResource("4_ehp8q")
CameraOffset = Vector2(0, 32)
_bossPortraitTexture = ExtResource("4_at5iq")
Health = 200.0
metadata/_edit_group_ = true

View file

@ -0,0 +1,12 @@
[gd_scene format=3 uid="uid://cec8gr3m3q3d0"]
[node name="SceenFader" type="CanvasLayer"]
[node name="ColorRect" type="ColorRect" parent="."]
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
mouse_filter = 2
color = Color(0, 0, 0, 1)

File diff suppressed because one or more lines are too long

View file

@ -1,11 +1,16 @@
using System.Threading.Tasks;
using Cirno.Scripts.Resources;
using Godot;
using GTweens.Builders;
using GTweensGodot.Extensions;
public partial class GlobalState : Node
{
public static GlobalState Instance { get; private set; }
public Node CurrentScene { get; set; }
private ColorRect _fader { get; set; }
public override void _Ready()
{
@ -16,6 +21,8 @@ public partial class GlobalState : Node
Viewport root = GetTree().Root;
// Using a negative index counts from the end, so this gets the last child node of `root`.
CurrentScene = root.GetChild(-1);
_fader = CreateFader();
}
public void GotoScene(string path)
@ -28,16 +35,26 @@ public partial class GlobalState : Node
// The solution is to defer the load to a later time, when
// we can be sure that no code from the current scene is running:
CallDeferred(MethodName.DeferredGotoScene, path, new MapStartDataResource());
//CallDeferred(MethodName.DeferredGotoScene, path, new MapStartDataResource());
GoToScene(path, new MapStartDataResource());
}
public void GoToScene(string path, MapStartDataResource startData)
{
// TODO: Implement startdata usage
CallDeferred(MethodName.DeferredGotoScene, path, startData);
GTweenSequenceBuilder.New()
//.Append(_fader.TweenModulateAlpha(0, 0f))
.Append(_fader.TweenModulateAlpha(1, 0.5f))
.AppendCallback(() =>
{
CallDeferred(MethodName.DeferredGotoScene, path, startData);
})
.Build()
.PlayUnpausable();
//CallDeferred(MethodName.DeferredGotoScene, path, startData);
}
private void DeferredGotoScene(string path, MapStartDataResource startData = null)
{
// It is now safe to remove the current scene.
@ -63,10 +80,43 @@ public partial class GlobalState : Node
// Call deferred if it gives issues
DeferredAddStartDataToGameManager(startData);
}
FadeIn();
}
private void DeferredAddStartDataToGameManager(MapStartDataResource resource)
{
GameManager.Instance.ApplyMapStartData(resource);
}
private ColorRect CreateFader()
{
var canvas = new CanvasLayer();
canvas.ProcessMode = ProcessModeEnum.Always;
var rect = new ColorRect();
rect.SetAnchorsPreset(Control.LayoutPreset.FullRect);
rect.Color = new Color(Colors.Black, 1f);
rect.ProcessMode = ProcessModeEnum.Always;
rect.Modulate = new Color(0,0,0,0);
rect.MouseFilter = Control.MouseFilterEnum.Ignore;
canvas.CallDeferred("add_child", rect);
this.CallDeferred("add_child", canvas);
return rect;
}
public void FadeOut()
{
_fader.TweenModulateAlpha(1, 0.5f).PlayUnpausable();
}
public void FadeIn()
{
_fader.TweenModulateAlpha(0, 1f).PlayUnpausable();
}
}

View file

@ -0,0 +1,8 @@
using Godot;
namespace Cirno.Scripts.UI;
public partial class ScreenFader : Control
{
}

View file

@ -0,0 +1 @@
uid://cq6jj3lsr7m0d