Godot Version
Godot Engine v4.4.1.stable.mono.official
Question
Just starting out. My goal is to have a game board that automatically generates a multitude of cells as child nodes under it. This is working well.
The issue is that these child nodes called “Square.cs” are not showing up despite having a sprite attached, being in the scene and having CanvasItem set to visible.
Here is a photo of the scene view showing that the squares have no textures attached but the node type does:
Any help is appreciated!
This is my code for creating the game board:
using Godot;
using System;
using System.Runtime.CompilerServices;
using System.Security.Cryptography.X509Certificates;public partial class Board : Node2D
{
public const int gameBoardHeight = 3;
public const int gameBoardWidth = 3;public const int squareSize = 16;
private Square[,] gameBoard;public override void _Ready()
{
gameBoard = new Square[gameBoardHeight, gameBoardWidth];
PopulateBoard();
}public void PopulateBoard()
{
Vector2 boardPosition = GlobalPosition;
int xOffset = 0;
int yOffset = 0;
GD.Print("Starting position: " + boardPosition);for (int x = 0; x < gameBoardHeight; x++) { for (int y = 0; y < gameBoardWidth; y++) { xOffset = x * squareSize; yOffset = y * squareSize; var square = new Square(new Vector2(boardPosition.X + xOffset, boardPosition.Y + yOffset)); AddChild(square); GD.Print("Added square at: " + square.Position.X + ", " + square.Position.Y); } } ViewChildren();
}
public void ViewChildren()
{
foreach (Node2D _childNode in GetChildren())
{
GD.Print("Child: " + _childNode.Name);
// GD.Print(“Child position” + _childNode.GlobalPosition);
}
}