Change background color

I hope a simple question:

How do I change the background color depending on where the character is on a large top down 2d scene?

Explanation:

I have a large “open world” scene with multiple areas. Would like the background color to change when I enter the “winter area” or the “ocean area”

Thanks,

1 Like

So the action is this

Simpler solution I can think right now is to have 2-4 rectangles, one for each weather. Position them into your map, and turn their opacity to 0.

Then each time your player collides with one, just have an action to change the background colour.

If you are good with variables, you can just have 1 rectangle asset with different variables.

If you don’t want to have rectangles, you can maybe change the colour with the coordinates of the character.

There are many solutions. Keep in mind that the colour changes immediately, not sure if there is a way to tween the background colour. If you use an image, or a tiled sprite as your background it would be easier to control the effects, I think.

3 Likes

Hi @Digitalstickmans - you can smoothly change the background colour using lerp


r,g and b are global number variables
this changes the colour from black to red as they all start on 0

2 Likes

Hey @Digitalstickmans and @petlimpet

Thanks very much for both of your suggestions, it worked really well with the rectangles and lerp! I’ve got the example working in my game, now just have to replicate it for each location.

2 Likes

Thanks! Didn’t know about Lerp, will try it

1 Like