scene manager
This commit is contained in:
@@ -6,10 +6,13 @@ public partial class Menu : Control
|
||||
[Export] AnimationPlayer anim;
|
||||
[Export] Panel pause;
|
||||
[Export] Panel trick;
|
||||
[Export] PackedScene principal;
|
||||
[Export] CharacterBody2D player;
|
||||
Node parent;
|
||||
|
||||
// Called when the node enters the scene tree for the first time.
|
||||
public override void _Ready()
|
||||
{
|
||||
parent = player.GetParent().GetParent();
|
||||
}
|
||||
|
||||
// Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
@@ -32,7 +35,10 @@ public partial class Menu : Control
|
||||
|
||||
public void ExitDown()
|
||||
{
|
||||
GetTree().ChangeSceneToPacked(principal);
|
||||
GetTree().Paused = false;
|
||||
parent.Call("ToPrincipalFunc");
|
||||
//EmitSignal("ToPrincipalEventHandler");
|
||||
//GetTree().ChangeSceneToPacked(principal);
|
||||
}
|
||||
|
||||
public void Res()
|
||||
|
||||
@@ -10,7 +10,7 @@ public partial class Player : CharacterBody2D
|
||||
[Export] TextureProgressBar bar;
|
||||
[ExportGroup("controls")]
|
||||
[Export] Control menu;
|
||||
[Export] PackedScene principal;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -5,12 +5,14 @@ public partial class Principal : Control
|
||||
{
|
||||
[Export] Panel sub;
|
||||
[Export] Panel credit;
|
||||
[Export] PackedScene play;
|
||||
|
||||
Node parent;
|
||||
|
||||
// Called when the node enters the scene tree for the first time.
|
||||
public override void _Ready()
|
||||
{
|
||||
|
||||
parent = GetParent();
|
||||
sub.Visible = false;
|
||||
}
|
||||
|
||||
// Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
@@ -20,6 +22,7 @@ public partial class Principal : Control
|
||||
|
||||
public void EnterPressed()
|
||||
{
|
||||
GD.Print("wefwef");
|
||||
sub.Visible = true;
|
||||
}
|
||||
|
||||
@@ -37,7 +40,9 @@ public partial class Principal : Control
|
||||
|
||||
public void PlayPressed()
|
||||
{
|
||||
GetTree().ChangeSceneToPacked(play);
|
||||
parent.Call("ToCityFunc");
|
||||
//EmitSignal("ToCityEventHandler");
|
||||
//GetTree().ChangeSceneToPacked(play);
|
||||
}
|
||||
|
||||
public void ExitGlobPressed()
|
||||
|
||||
43
script/SceneManager.cs
Normal file
43
script/SceneManager.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using Godot;
|
||||
using System;
|
||||
|
||||
public partial class SceneManager : Node
|
||||
{
|
||||
PackedScene principal ;
|
||||
PackedScene city;
|
||||
Node actuel;
|
||||
|
||||
|
||||
[Signal] public delegate void ToPrincipalEventHandler();
|
||||
[Signal] public delegate void ToCityEventHandler();
|
||||
// Called when the node enters the scene tree for the first time.
|
||||
public override void _Ready()
|
||||
{
|
||||
Callable PrincipalCallable = new Callable(this, MethodName.ToPrincipalFunc);
|
||||
Connect(SignalName.ToPrincipal, PrincipalCallable);
|
||||
|
||||
Callable CityCallable = new Callable(this, MethodName.ToCityFunc);
|
||||
Connect(SignalName.ToCity, CityCallable);
|
||||
|
||||
|
||||
principal = (PackedScene)ResourceLoader.Load("res://scene/principal.tscn");
|
||||
city = (PackedScene)ResourceLoader.Load("res://scene/city.tscn");
|
||||
actuel = principal.Instantiate();
|
||||
AddChild(actuel);
|
||||
|
||||
}
|
||||
|
||||
public void ToPrincipalFunc()
|
||||
{
|
||||
actuel.QueueFree();
|
||||
actuel = principal.Instantiate();
|
||||
AddChild(actuel);
|
||||
}
|
||||
|
||||
public void ToCityFunc()
|
||||
{
|
||||
actuel.QueueFree();
|
||||
actuel = city.Instantiate();
|
||||
AddChild(actuel);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user