clean up Scene code
This commit is contained in:
parent
04026c9381
commit
f27a3c9b6f
1 changed files with 4 additions and 16 deletions
|
@ -5,31 +5,21 @@ extends Node2D
|
||||||
|
|
||||||
@onready var current_scene = $CurrentScene
|
@onready var current_scene = $CurrentScene
|
||||||
#@onready var scene_transition = $ScreenTransition/AnimationPlayer
|
#@onready var scene_transition = $ScreenTransition/AnimationPlayer
|
||||||
var next_scene = null
|
|
||||||
|
|
||||||
var player
|
var player
|
||||||
var player_location : Vector2 = Vector2(0,0)
|
|
||||||
var player_direction : float = 1
|
|
||||||
|
|
||||||
|
func transition_to_scene(new_scene: PackedScene, spawn_location = Vector2(0,0), spawn_direction = 1):
|
||||||
|
|
||||||
func transition_to_scene(new_scene: PackedScene, spawn_location:Vector2, spawn_direction:float ):
|
|
||||||
next_scene = new_scene
|
|
||||||
player_location = spawn_location
|
|
||||||
player_direction = spawn_direction
|
|
||||||
#screen_transition.play('FadeToBlack')
|
#screen_transition.play('FadeToBlack')
|
||||||
if(current_scene.get_child(0)):
|
if(current_scene.get_child(0)):
|
||||||
current_scene.get_child(0).queue_free()
|
current_scene.get_child(0).queue_free()
|
||||||
current_scene.add_child(next_scene.instantiate())
|
current_scene.add_child(new_scene.instantiate())
|
||||||
|
|
||||||
#region Spawn Player
|
#region Spawn Player
|
||||||
|
|
||||||
if (player):
|
if (player):
|
||||||
player.teleport(player_location, player_direction)
|
player.teleport(spawn_location, spawn_direction)
|
||||||
else:
|
else:
|
||||||
player = $CurrentScene.find_child("player",true)
|
player = $CurrentScene.find_child("player",true)
|
||||||
if (player):
|
if (player):
|
||||||
player.teleport(player_location, player_direction)
|
player.teleport(spawn_location, spawn_direction)
|
||||||
else:
|
else:
|
||||||
if (InitialPlayer):
|
if (InitialPlayer):
|
||||||
player = InitialPlayer.instantiate()
|
player = InitialPlayer.instantiate()
|
||||||
|
@ -37,9 +27,7 @@ func transition_to_scene(new_scene: PackedScene, spawn_location:Vector2, spawn_d
|
||||||
add_child(player)
|
add_child(player)
|
||||||
else:
|
else:
|
||||||
printerr("No Initial player found")
|
printerr("No Initial player found")
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
func _on_ready():
|
func _on_ready():
|
||||||
transition_to_scene(InitialMap,Vector2(0,0),1)
|
transition_to_scene(InitialMap,Vector2(0,0),1)
|
||||||
|
|
Loading…
Reference in a new issue