I want to the change the color of progress bar progress, any idea?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By yeeshu06
:warning: Old Version Published before Godot 3 was released.

I have a progress bar within canvas layer. I want to change the color…as the time goes low. How can i do this? thanks

:bust_in_silhouette: Reply From: Skyfrit

You can change the foreground and background color in Inspector panel.(If it doesn’n update in the editor, try change the progress bar value.)

enter image description here

And you can use Tween or AnimationPlayer to change color as the time goes low.

func _ready():
	tween.interpolate_method(progressbar.get("custom_styles/fg"), "set_bg_color", Color("0081ff"), Color("ffffff"), 1, Tween.TRANS_LINEAR, Tween.EASE_IN_OUT)
	tween.start()

func _on_Tween_tween_step( object, key, elapsed, value ):
	progressbar.update()
:bust_in_silhouette: Reply From: CakeLover

I used this:

extends ProgressBar

func _set(property:String,val):
	if(property=="value"):
		value=val

		self.get("custom_styles/fg").set_bg_color(Color(
			1.0 if ratio<0.5 else (2 - 2*ratio),
			1.0 if ratio>0.5 else (2*ratio),
			0,1
		))

it gave me clear bright colors like this:
enter image description here

Hope it helps :slight_smile: