Scene transitions

This commit is contained in:
2023-09-11 11:17:52 -07:00
parent 28a29a88fe
commit ba9c1e320e
10 changed files with 1596 additions and 884 deletions

View File

@@ -8,9 +8,16 @@ public partial class Main : Node
public Array<PackedScene> Levels;
[Export]
public PackedScene GameManager;
[Export]
private Label _fpsCounter;
public int NumberOfPlayers = 0;
public override void _Process(double delta)
{
_fpsCounter.Text = $"FPS: {Engine.GetFramesPerSecond()}";
}
public void LoadLevel(int indexToLoad, int numberOfPlayers)
{
var sceneToLoad = Levels.ElementAt(indexToLoad);
@@ -26,6 +33,10 @@ public partial class Main : Node
bgmPlayer.ProcessMode = ProcessModeEnum.Always;
bgmPlayer.SetBGMFromFilepath("Audio/BGM/LevelTheme.ogg");
bgmPlayer.PlayBGM();
var animationNode = GetNode<AnimationPlayer>("SceneTransition/AnimationPlayer");
animationNode.Play($"Level{indexToLoad + 1}");
animationNode.AnimationFinished += EnableCharacterSelect;
}
public void LoadNextLevel(int currentSceneIndex)
@@ -33,8 +44,10 @@ public partial class Main : Node
if (currentSceneIndex < Levels.Count())
{
var currentScene = Levels.ToList().ElementAt(currentSceneIndex);
var nextScene = currentSceneIndex + 1;
CallDeferred(nameof(DeferredGoToScene), Levels.ElementAt(nextScene));
CallDeferred(nameof(DeferredGoToScene), Levels.ElementAt(currentSceneIndex));
var animationNode = GetNode<AnimationPlayer>("SceneTransition/AnimationPlayer");
animationNode.Play($"Level{currentSceneIndex + 1}");
animationNode.AnimationFinished += EnableCharacterSelect;
}
}
private void DeferredGoToScene(PackedScene sceneToAdd)
@@ -44,9 +57,6 @@ public partial class Main : Node
var nextScene = GD.Load<PackedScene>(sceneToAdd.ResourcePath);
var newScene = nextScene.Instantiate();
GetTree().Root.AddChild(newScene);
var animationNode = GetNode<AnimationPlayer>("SceneTransition/AnimationPlayer");
animationNode.Play($"Level{Levels.IndexOf(nextScene) + 1}");
animationNode.AnimationFinished += EnableCharacterSelect;
}