Working with Tint maps

Tint maps are used to alter the colour of 2D sprites dynamically as they move around a scene, allowing for some nice lighting effects. In this tutorial, we'll update the 2D Demo so that we can have the Player character get darker as he moves to either side of the scene. Note that this feature is only possible for games made using Unity 2D, as set within the Camera settings section of the Settings Manager.

We'll be making use of the following texture to tint the scene. Right-click on it to download it to your Assets folder:

Select it within Unity, and view it's Inspector window. Change the Texture Type to Advanced, and check Read/Write Enabled. The Tint map will not work with this texture unless we make these changes. Click Apply at the bottom.

We'll now need to load in the 2D demo's managers, which we can do from the top toolbar, and choosing Adventure Creator -> Getting started -> Load 2D Demo managers.

Now open the 2D Demo scene - in your Project window, choose Assets -> AdventureCreator -> 2D Demo -> Scenes -> Park.

We'll need to work with the Scene Manager within the Game Editor windor. Click on the Sceme tab, and look for the Default Tint map field under Scene settings. Click Create to automatically create and assign a new Tint map.

Select the new Tint map (named "Default TintMap") and view it's Inspector. Drag the 2DDemo-Tint texture we downloaded into the Texture to use field:

In the Scene Window, you can see that it is placed behind the rest of the scene geometry for us. You can move it in front if you prefer - the Disable mesh renderer? box in the Inspector will prevent it from being visible during gameplay. Using the Rectangle manipulator or the Scale / Transform manipulators, stretch it out so that it spans the same width and height as the background sprites.

Now we just need to tell our Player prefab that it can make use of this Tint map. The 2D Demo game's Player prefab can be found in Assets -> Adventure Creator -> 2D Demo -> Resources -> Brain2D. Select the prefab, and find the Sprite child object within it's hierarchy. At the bottom of it's Component stack in the Inspector, add the Follow Tint Map script, and leave the settings at their default values.

The Player's sprite will now get darker as he nears the edges of the scene. This is because the sides of the 2DDemo-Tint texture have dark edges, and is tinting the sprite in the same way.

Tint maps can be changed in game: the Engine: Change scene setting Action can be used to change the scene's default Tint map, and the Object: Change Tint map can be used to change the settings within a FollowTintMap script component. Be sure to add the Remember Visibility component to any FollowTintMap that is changed in this way - this will ensure changes made to it are stored in save games.

"Adventure Creator" and this website are copyright Chris Burton, ICEBOX Studios

Go to top