Pong/Scripts/Managers/MainMenuManager.cs

29 lines
694 B
C#
Raw Normal View History

using Godot;
namespace Pong.Scripts.Managers;
public partial class MainMenuManager : VBoxContainer
{
// Called when the node enters the scene tree for the first time.
public override void _Ready()
{
GetTree().Root.SizeChanged += AdaptUiToScreenResolution;
AdaptUiToScreenResolution();
}
/// <summary>
/// code that executes when the start button is pressed. this loads the Pong scene to the root
/// of the scene tree.
/// </summary>
private void OnButtonPressed()
{
GetTree().Root.SizeChanged -= AdaptUiToScreenResolution;
GetTree().ChangeSceneToFile("res://Scenes/Pong.tscn");
}
private void AdaptUiToScreenResolution()
{
Size = DisplayServer.WindowGetSize();
}
}