StickerClone/core/sceneInstance.gd

37 lines
1 KiB
GDScript3
Raw Normal View History

2024-07-23 15:49:31 +00:00
extends Node2D
2024-07-25 12:08:44 +00:00
2024-07-23 15:49:31 +00:00
@export var InitialPlayer :PackedScene
@export var InitialMap :PackedScene
@onready var current_scene = $CurrentScene
#@onready var scene_transition = $ScreenTransition/AnimationPlayer
var player
2024-07-23 19:50:52 +00:00
func transition_to_scene(new_scene: PackedScene, spawn_location = Vector2(0,0), spawn_direction = 1):
2024-07-23 15:49:31 +00:00
#screen_transition.play('FadeToBlack')
2024-07-24 21:43:32 +00:00
if(current_scene.get_child_count() > 0 and current_scene.get_child(0)):
2024-07-23 15:49:31 +00:00
current_scene.get_child(0).queue_free()
2024-07-23 19:50:52 +00:00
current_scene.add_child(new_scene.instantiate())
2024-07-23 15:49:31 +00:00
#region Spawn Player
if (player):
2024-07-23 19:50:52 +00:00
player.teleport(spawn_location, spawn_direction)
2024-07-23 15:49:31 +00:00
else:
player = $CurrentScene.find_child("player",true)
if (player):
2024-07-23 19:50:52 +00:00
player.teleport(spawn_location, spawn_direction)
2024-07-25 12:08:44 +00:00
else: #Spawn the player if there is none
2024-07-23 15:49:31 +00:00
if (InitialPlayer):
player = InitialPlayer.instantiate()
player.set_name("player")
add_child(player)
else:
printerr("No Initial player found")
#endregion
func _on_ready():
transition_to_scene(InitialMap,Vector2(0,0),1)
2024-07-25 12:08:44 +00:00
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)