Система перехода между сценами. И главное меню. Типа.

This commit is contained in:
Евгений Титаренко 2024-08-25 12:27:06 +03:00
parent 8e4304ebc6
commit f45ebbceb6
7 changed files with 172 additions and 1 deletions

50
scripts/Startup.cs Normal file
View file

@ -0,0 +1,50 @@
using Godot;
using System;
public partial class Startup : Node2D
{
private enum State
{
Default,
Transition
}
private State _state = State.Default;
private ColorRect _colorRect;
private AudioStreamPlayer _music;
private double _transitionTimeout = 0;
// Called when the node enters the scene tree for the first time.
public override void _Ready()
{
_colorRect = (ColorRect)FindChild("ColorRect");
_music = (AudioStreamPlayer)FindChild("AudioStreamPlayer");
}
// Called every frame. 'delta' is the elapsed time since the previous frame.
public override void _PhysicsProcess(double delta)
{
if (_state == State.Transition)
{
_transitionTimeout += delta;
// _colorRect.Color = _colorRect.Color.Lerp(new Color(0, 0, 0, 255), (float)_transitionTimeout/2);
_colorRect.Color = new Color(0, 0, 0, Mathf.Lerp(0, 1, (float)_transitionTimeout/2));
_music.VolumeDb = Mathf.Lerp(0, -41, (float)_transitionTimeout/2);
if (_music.VolumeDb < -40)
{
GetNode<SceneManager>("/root/SceneManager").SwitchScene("Day1");
}
}
}
public override void _Input(InputEvent @event)
{
if (@event.IsActionPressed("Interact"))
{
_state = State.Transition;
}
}
}