StickerClone/core/sceneInstance.gd
2024-07-29 15:25:36 +02:00

39 lines
1.1 KiB
GDScript

extends Node2D
@export var InitialPlayer :PackedScene
@export var InitialMap :PackedScene
@onready var current_scene = $CurrentScene
#@onready var scene_transition = $ScreenTransition/AnimationPlayer
var player:Object
func transition_to_scene(new_scene: PackedScene, spawn_location = Transform2D.IDENTITY, spawn_direction = 1):
#screen_transition.play('FadeToBlack')
if (new_scene):
#if(current_scene.get_child_count() > 0 and current_scene.get_child(0)):
#current_scene.get_child(0).queue_free()
current_scene.add_child(new_scene.instantiate())
else:
printerr("No New Scene")
#region Spawn Player
if (player):
player.teleport(spawn_location, spawn_direction)
else:
player = $CurrentScene.find_child("player",true)
if (player):
player.teleport(spawn_location, spawn_direction)
else: #Spawn the player if there is none
if (InitialPlayer):
player = InitialPlayer.instantiate()
player.set_name("player")
current_scene.get_child(0).add_child(player)
else:
printerr("No Initial player found")
#endregion
func _on_ready():
transition_to_scene(InitialMap,Vector2(0,0),1)