Godot Version
4.6.2.stable
Question
I have the Atlas set up and I want a random coordinate in the Atlas to be assigned to each button. Below is the code I have so far:
If you share code, please wrap it inside three backticks or replace the code in the next block:
extends Control
@onready var upgrade_canvas_layer: CanvasLayer = $".."
@onready var button_1: Button = $HBoxContainer/Button1
@onready var button_2: Button = $HBoxContainer/Button2
@onready var button_3: Button = $HBoxContainer/Button3
@onready var h_box_container: HBoxContainer = $HBoxContainer
var upgrade_buttons = [button_1, button_2, button_3]
var pick_die
func populate_buttons():
for i in h_box_container.get_children():
pick_die = Globals.types_of_die.keys().pick_random()
i.text = str(pick_die)
#Insert code that updates the region coordinates from the Atlas
i.region = Rect2(Globals.types_of_die[pick_die][0], Globals.types_of_die[pick_die][1], 16, 16) #<---doesn't work
This is what I have in Globals:
var types_of_die = {
"Plastic D2": [0, 64],
"Plastic D3": [0, 48],
"Plastic D4": [0, 32],
"Plastic D5": [0, 16],
"Plastic D6": [0, 0],
"Gold D2": [0, 144],
"Gold D3": [0, 128],
"Gold D4": [0, 112],
"Gold D5": [0, 96],
"Gold D6": [0, 80],
"Diamond D2": [0, 224],
"Diamond D3": [0, 208],
"Diamond D4": [0, 192],
"Diamond D5": [0, 176],
"Diamond D6": [0, 160],
}







