From d275f97bf78f1a292354f824109fa36f2c072d1f Mon Sep 17 00:00:00 2001 From: Jonathan Herrewijnen Date: Thu, 27 Oct 2022 22:34:41 +0200 Subject: [PATCH] Again reworking map loading system. Some progress --- Global.gd | 22 ++++++++++++++++------ Maps/river_intersection.tscn | 1 + MiscCodes/KinematicBody2D.gd | 3 ++- MiscCodes/Tilemap_CameraView.gd | 6 ++---- Other/base_tilemap/base_tilemap.tscn | 2 +- 5 files changed, 22 insertions(+), 12 deletions(-) diff --git a/Global.gd b/Global.gd index 2dc63ec..63c8164 100644 --- a/Global.gd +++ b/Global.gd @@ -51,12 +51,22 @@ func RemoveScene(scene): camera.remove_child(scene) func AddMap(load_on, mapname): - var maps = load(mapname).instance().get_children() - for i in maps: - load_on.add_child(i) - print('Added ', i) - for _i in self.get_children(): - print("Nodes visible at addMap ", _i) + for _i in get_parent().get_children(): + print("Nodes visible before addMap ", _i) + print("Adding map ", mapname) + var addedscene = load(mapname).instance() + #addedscene.set_position(Vector2(-617,-300)) + get_parent().add_child(addedscene) + for _i in get_parent().get_children(): + print("Nodes visible at addMap ", _i) +# var maps = load(mapname).instance().get_children() +# for i in maps: +# load_on.add_child(i) +# print('Added ', i) +# +# #There's a chance that 1) this is an on-load problem 2) the nodes never get instanced/loaded +# for _i in self.get_children(): +# print("Nodes visible at addMap ", _i) #Go to scene by name func GoToScene(scene): diff --git a/Maps/river_intersection.tscn b/Maps/river_intersection.tscn index c85cda0..a7b422f 100644 --- a/Maps/river_intersection.tscn +++ b/Maps/river_intersection.tscn @@ -145,6 +145,7 @@ resource_local_to_scene = true 6/z_index = 0 [node name="Map1" type="Node2D"] +z_index = -1 [node name="background" type="TileMap" parent="."] tile_set = ExtResource( 3 ) diff --git a/MiscCodes/KinematicBody2D.gd b/MiscCodes/KinematicBody2D.gd index 2bce40b..ba1f082 100644 --- a/MiscCodes/KinematicBody2D.gd +++ b/MiscCodes/KinematicBody2D.gd @@ -8,7 +8,8 @@ onready var background_map = get_node("../background") onready var vegetation_map = get_node("../vegetation") onready var interaction_map = get_node("../interaction_map") onready var player_interaction_map = get_node("../player_interaction") -onready var cell_size = background_map._get_cell_size() +#onready var cell_size = background_map._get_cell_size() +onready var cell_size = 32 var velocity = Vector2() var world_position diff --git a/MiscCodes/Tilemap_CameraView.gd b/MiscCodes/Tilemap_CameraView.gd index ae0b5e7..ccb68e5 100644 --- a/MiscCodes/Tilemap_CameraView.gd +++ b/MiscCodes/Tilemap_CameraView.gd @@ -5,13 +5,11 @@ onready var player = get_node("/root/base_scene/Player") onready var background_map = get_node("/root/base_scene/background") onready var screen_size = self.get_viewport_rect().size -func _init(): +func _ready(): var map_name = "res://Maps/river_intersection.tscn" print(self) Global.AddMap(self, map_name) - -func _ready(): - var map_name = "res://Maps/river_intersection" + calculate_bounds() Global.current_camera = self $dev_statistics.visible = Global.dev_stats diff --git a/Other/base_tilemap/base_tilemap.tscn b/Other/base_tilemap/base_tilemap.tscn index 168f953..9ac09ed 100644 --- a/Other/base_tilemap/base_tilemap.tscn +++ b/Other/base_tilemap/base_tilemap.tscn @@ -27,6 +27,7 @@ script = ExtResource( 6 ) [node name="Camera2D" type="Camera2D" parent="."] position = Vector2( 705.297, 1197.88 ) z_index = 15 +z_as_relative = false current = true limit_left = 0 limit_top = 0 @@ -132,7 +133,6 @@ visibility_mode = 1 script = ExtResource( 4 ) [node name="dev_statistics" type="MarginContainer" parent="Camera2D"] -visible = false margin_left = -617.0 margin_top = -300.0 margin_right = 612.0