so without going into too many details(Details are below the line) I want to set the Region Size for a Texture button and then move that region around. I have tried searching up the answer but I can't. I tried a code like this but I'm pretty sure that's just not right. Can somebody please tell me the way to do this?
button.region_custom_minimum_size = Vector2(16,16)
button.region_position = Vector2(spriteWidth * (spellIndex - 1), 0)
If you need context, I am making a game where you have spells you can unlock and choose to place in a loadout so you can quickly use that spell I have an array that tells me what the current spell loadout is.
depending on the Array I will have a different Button Texture for each spell slot, All my spell textures are on one sprite sheet and I use an atlas texture for the Textured button. When the loadout changes I want to move the atlas texture region to one of the spells on the SpriteSheet.||||spoiler||||
This is the full code if you need it also I do know I could set the region in the editor but just to be safe I'm asking here.
extends Control
@export var sword: Sprite2D
@onready var spellloadout = Global.SpellLoadout
func _ready():
# Sets the spell loadout on another (Delete this later)
spellloadout = [1, 2, 3, 4, 5, 6]
for i in range(1, 7):
var spellIndex = spellloadout[i - 1]
var button = get_node("CanvasLayer/SpellButton" + str(i))
var spriteWidth = 16
var spriteHeight = 16
button.region_custom_minimum_size = Vector2(16,16)
button.region_position = Vector2(spriteWidth * (spellIndex - 1), 0)