How to change the stretch of a sprite in one direction only in code?

Godot Version

4.2.2

Question

I’m making a scale that displays stamina. I need the initially small scale sprite to stretch upwards proportionally to how much stamina the player has left. But the problem is that “scale” the parameter stretches the scale vertically both up and down! So the scale simply goes beyond its own limits… How can I fix this?

Scale should be a Vector2:

sprite.scale = Vector2(1, 2)

Nothing has changed. The sprite still stretches in both directions “y”. But I need it to extend only upwards and NOWHERE else…

You need to set the offset of your sprite at the bottom of it so scale only change it’s size upward.