Children are not added

This commit is contained in:
Jonathan Herrewijnen 2022-10-17 23:29:08 +02:00
parent 91d651b3f3
commit eb513f9db9
4 changed files with 24 additions and 9 deletions

View File

@ -50,12 +50,13 @@ func RemoveScene(scene):
var camera = get_node("/root/base_scene/Camera2D") var camera = get_node("/root/base_scene/Camera2D")
camera.remove_child(scene) camera.remove_child(scene)
func AddMap(mapname): func AddMap(load_on, mapname):
var maps = load(mapname).instance().get_children() var maps = load(mapname).instance().get_children()
for i in maps: for i in maps:
print(get_tree().get_root()) load_on.add_child(i)
get_tree().get_root().add_child(i)
print('Added ', i) print('Added ', i)
for _i in self.get_children():
print("Nodes visible at addMap ", _i)
#Go to scene by name #Go to scene by name
func GoToScene(scene): func GoToScene(scene):

View File

@ -9,4 +9,3 @@ func _on_Btn_PlayGame_pressed():
func _on_Btn_LoadGame_pressed(): func _on_Btn_LoadGame_pressed():
Global.GoToScene("loadgame_screen") Global.GoToScene("loadgame_screen")

View File

@ -5,6 +5,11 @@ onready var player = get_node("/root/base_scene/Player")
onready var background_map = get_node("/root/base_scene/background") onready var background_map = get_node("/root/base_scene/background")
onready var screen_size = self.get_viewport_rect().size onready var screen_size = self.get_viewport_rect().size
func _init():
var map_name = "res://Maps/river_intersection.tscn"
print(self)
Global.AddMap(self, map_name)
func _ready(): func _ready():
var map_name = "res://Maps/river_intersection" var map_name = "res://Maps/river_intersection"
calculate_bounds() calculate_bounds()
@ -22,7 +27,7 @@ var max_y_pixel = 0
#function that calculates the borders/bounds of the map #function that calculates the borders/bounds of the map
func calculate_bounds(): func calculate_bounds():
for _i in self.get_parent().get_children(): for _i in self.get_children():
print("Nodes visible ", _i) print("Nodes visible ", _i)
var used_cells = background_map.get_used_cells() var used_cells = background_map.get_used_cells()
for pos in used_cells: for pos in used_cells:

View File

@ -1,8 +1,18 @@
extends Node2D extends Node2D
func _init(): #func realize():
var map_name = "res://Maps/river_intersection.tscn" # print("At ready")
Global.AddMap(map_name) # for _i in self.get_children():
# print("Nodes visible at init ", _i)
#
#func _init():
# var map_name = "res://Maps/river_intersection.tscn"
# Global.AddMap(self, map_name)
# realize()
#
#func _ready():
# realize()
# for _i in self.get_children(): # for _i in self.get_children():
# print("Nodes visible ",_i) # print("Nodes visible ",_i)
# if _i is TileMap: # if _i is TileMap: