How do I brighten the color of the background slightly when collecting an item?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By GamesByMike

I’m trying to make it when the player collects an item, the background gets slightly brighter every time an item is collected:

Here is my code so far:

extends Area2D

func _ready():
	RenderingServer.set_default_clear_color(Color.MIDNIGHT_BLUE)

func _on_body_entered(body):
	RenderingServer.set_default_clear_color(Color.MIDNIGHT_BLUE.lightened( + 0.05))
	queue_free()
:bust_in_silhouette: Reply From: HyperlinkYourHeart

I guess the result of that code is that the background gets slightly lighter the first time, but not after that? If so it is because you are setting the colour to the same 5% lighter than MIDNIGHT_BLUE every time. Try getting the current clear colour and lightening that:

func _on_body_entered(body):
    RenderingServer.set_default_clear_color(
        RenderingServer.get_default_clear_color().lightened( + 0.05)
    )
    queue_free()

That worked! Thank you so much!

GamesByMike | 2023-06-12 21:03