I want to make a grid container that can hold ice floats & water tiles. The ice floats are also containers that can hold fish and penguins. My idea was to make the whole game board a grid container, and then add ice float grid containers randomly, each with a panel child component that is the ice float texture,(same with the fish). However, when I add textures to the ice floats nothing shows up, and the fish float texture is just showing up in the corner of the screen.
extends Node
const GRID_CONTAINER_PATH = "PanelContainer/GridContainer"
const ICE_CONTAINER_PATH = "res://sr20f220030d8aws3.webp"
const GRID_COLUMNS = 8
const ICE_IMAGE_PATH = "res://iceblock2.jpeg"
const PENG_IMAGE_PATH = "res://sr20f220030d8aws3.webp"
const FISH_IMAGE_PATH = "res://fish.webp"
var fish = fish_image_tile(FISH_IMAGE_PATH)
var watertile = Panel.new()
var icetile = create_image_tile(ICE_IMAGE_PATH)
var icecontainer = GridContainer.new()
func _ready():
var container = get_node(GRID_CONTAINER_PATH)
if container:
container.columns = GRID_COLUMNS
for child in container.get_children():
child.queue_free()
for i in range(64):
var min_value = 0
var max_value = 25
var min_value2 = 0
var max_value2 = 100
var random_int = randi() % (max_value - min_value + 1) + min_value
var random_int2 = randi() % (max_value2 - min_value2 + 1) + min_value2
if random_int < 10:
container.add_child(watertile)
print("water printed.")
else:
container.add_child(icetile)
icetile.add_child(icecontainer)
var tile = create_image_tile(ICE_IMAGE_PATH)
container.add_child(tile)
print("ice printed.")
#if random_int2 > 20 and random_int2 < 40:
#icecontainer.add_child(fish)
#elif random_int2 > 40 and random_int2 < 80:
#icecontainer.add_child(fish)
#icecontainer.add_child(fish)
#elif random_int2 > 80 and random_int2 < 100:
#icecontainer.add_child(fish)
#icecontainer.add_child(fish)
#icecontainer.add_child(fish)
else:
print("Error: GridContainer node not found.")
func create_image_tile(image_path: String) -> Panel:
var panel = Panel.new()
#panel.rect_min_size = Vector2(5, 5)
var ice_texture_rect = TextureRect.new()
ice_texture_rect.stretch_mode = TextureRect.STRETCH_SCALE
#panel.stretch_mode = panel.STRETCH_SCALE
#texture_rect.rect_min_size = panel.rect_min_size
panel.add_child(ice_texture_rect)
return panel