platformer-game-test/src/Scripts/SpawnPoint.gd

31 lines
607 B
GDScript

extends Position2D
tool
export var node:PackedScene = null
onready var player_ref:Player = get_tree().current_scene.get_node("Player")
func _ready() -> void:
if Engine.editor_hint:
_spawn()
else:
player_ref.connect("died", self, "_on_Player_died")
func _on_VisibilityNotifier2D_screen_entered() -> void:
respawn()
func respawn():
var current_node = get_node("node")
if current_node == null and node != null:
_spawn()
else:
pass
func _on_Player_died():
if $VisibilityNotifier2D.is_on_screen():
respawn()
func _spawn():
var inst = node.instance()
inst.name = "node"
add_child(inst)