Godot Version
4.4.1
Question
I’m using a scene that’s basically a segment of a health, stamina, or mana meter, and I can put the scene in for each unit of said meter available. An exported value sets the meter type and the meter is meant to automatically change its appearance to fit said type.
Currently all the information for these meters are in a single texture sheet, so I can use an AtlasTexture to just get any part I want. Not only are there different meter types, but depending on whether its the start, middle, or end of a meter, the atlas coordinates change too. I began implementing automatic changes of atlas coordinates, every single instance of my scene had the changes applied. I want to know if there’s a way for me to get this to work without having to break up my atlas texture or make redundant scenes.
Here’s the code I got, which is basically just an outline where more functionality would be added later.
extends Node2D
@onready var sprite: TextureProgressBar = $sprite
enum Style {HEALTH, STAMINA, MANA}
enum Type {START, MID, ALTMID, END}
@export var meter: Style
@export var Segment: Type
@export var decrement: float:
set(value):
decrement = clamp(value,0.0,200.0)
func restyle(hp: float = 0.0, st: float = 0.0, mn: float = 0.0):
match meter:
Style.HEALTH:
sprite.value = hp - (90.0-decrement)
sprite.texture_progress.region = Rect2(96.0,0.0,32.0,32.0)
Style.STAMINA:
sprite.value = (st*10.0) - (90.0-decrement)
sprite.texture_progress.region = Rect2(96.0,32.0,32.0,32.0)
Style.MANA:
sprite.value = (mn*10.0) - (90.0-decrement)
match Segment:
Type.START:
sprite.texture_over.region = Rect2(0.0,32.0,32.0,32.0)
Type.MID:
sprite.texture_over.region = Rect2(32.0,32.0,32.0,32.0)
Type.END:
sprite.texture_over.region = Rect2(64.0,32.0,32.0,32.0)type or paste code here