← Pixel Dreamer Studio

Show a 0 to 1 ratio on a progress bar, and fill a ring or gauge from the angle you want

A TextureProgressBar rounds its value to step, which is 1 by default. Use 0 to 1 with step 0, then pick the fill mode and start angle for rings.

Set max_value = 1 and step = 0, then assign the ratio, or keep 0 to 100 and assign ratio * 100. In our Godot 4.7 test a TextureProgressBar with its defaults, max 100 and step 1, stored 0.37 as 0 and drew nothing. With max 1 and step still 1, 0.37 became 0 and 0.6 became 1, a full bar. With step 0 it kept 0.374 and filled 37.5%. For a ring, use Fill Mode Clockwise: it starts at the top, and radial_initial_angle 90 starts it at the right.

The code

Save it as ring_progress.gd. set_ratio() takes any Range node, sets it to 0 to 1 with no step and assigns the ratio. setup_ring() gives a TextureProgressBar a ring texture, a start angle (0 is the top, 90 the right), how many degrees a full bar covers, and the direction. For example: const RingProgress := preload("res://ring_progress.gd"), RingProgress.setup_ring($Cooldown, preload("res://addons/pd_hud124/textures/Ring/HUD_Ring_03.png")), then every frame RingProgress.set_ratio($Cooldown, time_left / cooldown). For a speed gauge with a gap at the bottom: RingProgress.setup_ring($Speed, tex, 225.0, 270.0).

extends RefCounted
## TextureProgressBar (and ProgressBar) helpers: show a 0-1 ratio without it being rounded away,
## and fill a ring or a gauge arc from the angle you want.


static func set_ratio(bar: Range, ratio: float) -> void:
	# a Range rounds value to its step, and step is 1 by default
	bar.min_value = 0.0
	bar.max_value = 1.0
	bar.step = 0.0
	bar.value = clampf(ratio, 0.0, 1.0)


static func setup_ring(bar: TextureProgressBar, tex: Texture2D, start_deg := 0.0, sweep_deg := 360.0, clockwise := true) -> void:
	bar.texture_progress = tex
	bar.fill_mode = TextureProgressBar.FILL_CLOCKWISE if clockwise else TextureProgressBar.FILL_COUNTER_CLOCKWISE
	bar.radial_initial_angle = start_deg  # 0 = top, 90 = right, 180 = bottom
	bar.radial_fill_degrees = sweep_deg
	bar.radial_center_offset = Vector2.ZERO

What we measured

TextureProgressBars on a CanvasLayer: a white 200 by 20 bar filling left to right, and a white ring 256 px wide. We counted the lit pixels, and for rings which 45 degree slice they were in, clockwise from the top. Two runs gave the same numbers.

Why it happens

TextureProgressBar is a Range node, like ProgressBar and the sliders. A Range snaps its value to the nearest multiple of step, and on a TextureProgressBar step starts at 1, so any value between 0 and 1 ends up as 0 or 1. That is easy to miss when a health or cooldown ratio is 0 to 1 and the bar's max is still 100 or 1. The radial fill modes measure angles in degrees from the top: radial_initial_angle is where the fill starts, turning clockwise, and radial_fill_degrees is how far a full bar reaches.

What to change

Rings and gauges to fill: 124 Sci-Fi HUD Elements has 24 rings and 10 gauges as white PNGs, ready for Godot 4. We used one of its rings in this test as the progress texture. It also comes inside Godot 4 Ready Kit.

Tested in Godot 4.7 with the Compatibility renderer.

Ready-made: 124 Sci-Fi HUD Elements has 24 rings and 10 gauges as white PNGs. We filled one of the rings as a TextureProgressBar in this test.

More how-tos: UI and HUD