Over the past few days I’ve been tinkering with the code of the game I’m working on and trying to come up with a way in which the colour of all the objects in a game can switch between colour schemes. I think I have a reasonably reliable solution.
Basically my main game controller has two sets of colours: a target colour set and a current colour set. The current colour set is the one that you see, as all the game objects refer to that when updating their colour tint values. The second set, the target colours, are a group of colours that the current colour set is trying to replicate.
Basically what this allows me to do is always refer objects in the scene to the one set of colours without having to worry about how they’re going to transition. The game controller object is constantly managing the colour palette, and all transitions are done there. While it makes for a fair bit of code on the game controller object, it massively reduces the code on everything else in the scene.
There’s a new build that shows this colour switching. It’s not a sudden process, as the game controller only changes the current colour set values by a small amount each frame. You can try this by pressing the “C” key on your keyboard. The image below links to the newest version, so if I’ve updated it since writing this then it may not work any more (but will likely be closer to completion.)