Total Newb needs help.

Godot Version

4.3

Question

` I am currently creating a mini-map interface for my game using a Grid Container node. I have set up a Table to represent the map. I decided not to use the TileLayer node because I want the mini-map to stretch and expand dynamically, as the map will change in size depending on the game situation. I felt that the Tile Map node wouldn’t work for this purpose.

If I am making this more complicated than necessary, please let me know.

Here is the code I have created so far. `

extends GridContainer


const PLAYERPANEL = "P"
const WALL = "W"
const FLOOR = "F"
const DOOR = "D"

var DoorScene = preload("res://door_panel.tscn")
var WallScene = preload("res://wall_panel.tscn")
var FloorScene = preload("res://floor_panel.tscn")
var PlayerPanelScene = preload("res://player_panel.tscn")



var map_data = [
	["W", "W", "W", "W", "W", "W", "W", "W", "W", "W"],
	["W", "F", "P", "F", "F", "F", "F", "F", "F", "W"],
	["W", "F", "F", "F", "F", "F", "F", "F", "F", "W"],
	["W", "F", "F", "F", "F", "F", "F", "F", "F", "W"],
	["W", "F", "F", "F", "F", "F", "F", "F", "F", "W"],
	["W", "F", "F", "F", "F", "F", "F", "F", "F", "W"],
	["W", "F", "F", "F", "F", "F", "F", "F", "F", "W"],
	["W", "F", "F", "F", "F", "D", "F", "F", "F", "W"],
	["W", "F", "F", "F", "F", "F", "F", "F", "F", "W"],
	["W", "W", "W", "W", "W", "W", "W", "W", "W", "W"],
]

func _ready():
	self.columns = map_data[0].size()
	for row in map_data:
		for cell in row:
			match cell:
				PLAYERPANEL:
					add_player_panel()
				WALL:
					add_wall_panel()
				FLOOR:
					add_floor_panel()
				DOOR:
					add_door()


func add_player_panel():
	var player_panel = PlayerPanelScene.instantiate()
	add_child(player_panel)



func add_wall_panel():
	var wall_panel = WallScene.instantiate()
	add_child(wall_panel)

func add_floor_panel():
	var floor_panel = FloorScene.instantiate()
	add_child(floor_panel)

func add_door():
	var door_panel = DoorScene.instantiate()
	add_child(door_panel)

My issue is that when the Player loads into the Scene, it does not appear on top of the player panel. After experimenting with the code, I’ve noticed that this problem occurs because the player node is a 2D Node rather than a Control Node.

When isolated in its own scene, the Player loads as expected on top of the player panel. However, when loading into the Main Screen, it either does not load inside the Container or loads incorrectly. Please refer to the attached images for clarification.



Can you show the code that add the player object into the scene?

Sorry, I should have explained. At one point, I had a function that initiated the player, similar to how I have my add door and add floor panel functions, which is why you see the Player Node being loaded.

At the moment, I have the player node saved in the player panel scene, and I think this was a workaround for my issue. Unfortunately, it does the same as if it was initiated via code by my Gridcontainer Script.

For refrence^

The only thing i can think is you have a piece of code that moves this character after the instantiation. Otherwise only looking into the project to investigate.

1 Like

Thank you for your efforts; honestly, I’m feeling quite lost because no single line of code mentions the player outside of the player movement code within the Player node script. I have a sneaking suspicion that this issue occurs when the player is being rendered on the screen.

When I change the Z index of the player to any value greater than 0, it seems to affect the player’s position on the map. It’s almost as if an index greater than 0 shifts the player’s position by a certain amount, while an index of 0 places the player in a different position. It’s quite perplexing!

I don’t think the z_index change is enough to cause this problem, if you want you can upload your project somewhere so i can try check what’s going on.