I am trying to change the background of my game based on the time of the day. I was thinking of using the “hr_counter” variable to dictate what color to display on the screen based on the hour of the day. The value of the “hr_counter” variable would start at zero (for midnight) and display the color on the very left of the gradient, then switches to every color to the right of it indicated by the markers shown below at different hours, then becomes white at noon, then goes backwards as the hours past noon progresses. Below is the gradient I want to use, which I found online:
The problem is, I have no idea what code to use to display the associated colors as an overlay on my game. I’m also not sure how to make the TextureRect opaque, which would allow me to see the game itself.
Okay, so you want the texturerect to be only one color at once, but the color changes throughout the day? You could use a CanvasModulate. Or a ColorRect with modulate.a (alpha) set to something less than 1 that goes over the entire screen. I assume when you say opaque (cannot be seen through), you mean translucent (partially transparent)? You don’t need to have the actual gradient on a TextureRect to accomplish this.
Modulation works like a multiply layer in a drawing software. If you want a different effect, you could look into Light2D or shaders.
All of my code is in the script attached to the “Time_Function” node. I added the following lines of code: @onready var canvas_modulate: CanvasModulate = $CanvasModulate
I’m assuming just putting in hours to the sample function doesn’t work? I’m not sure exactly what number should go into the sample function, but it might be a number between 0 and 1? You should divide hours by 24 and put it into the sample function.