Tutorials

Switchable Textures



When making a map for the Half-Life 1 engine it was possible to create an entity with a switchable texture. It was possible to create a lightswitch (func_button) for example that could switch between a "pressed state" texture and an "unpressed state" texture. It was also possible to create a television screen (func_wall) for example that could switch between different "channels". If you want to find out how this is possible in the Source engine, read on!

In this tutorial I'll show you how to make a lightswitch with a texture that changes when the switch is pressed. I assume you already created two textures.

Example:
news post image
news post image

I also assume you have some basic knowledge of the Source engine directory structure (you know where the tool vtex and your materialsrc and materials folders are located) and of creating a map in Hammer (you know how to create brushes, apply textures and insert entities). If not go read one of the excellent tutorials here on these subjects first!

Step 1: Creating the texture
1) Make sure your textures are called switch001.tga and switch002.tga and that they are in your materialsrc folder
2) Create a text file called switch.txt (in your materialsrc folder) and insert the following text:

"startframe" "1"
"endframe" "2"


3) Drag and drop the text file to vtex, the file switch.vtf is now created in your materials folder (alternatively use the command line vtex <materialsrc folder>\switch.txt).
4) Create a text file called switch.vmt (in your materials folder) and insert the following text:

"LightmappedGeneric"
{	
	"$baseTexture" "mydir/switch"
	"Proxies" 
	{
		"ToggleTexture" 
		{
			"toggleTextureVar" "$baseTexture" 
            			"toggleTextureFrameNumVar" "$frame" 
            			"toggleTextureShouldWrap" "0" 
		} 
	} 
}


Replace "mydir/switch" with the accurate location of your switch texture.

Step 2: Adding the lightswitch in your map
1) Use the Block Tool (Shift+B) to create a small brush and place it somewhere on a wall, and apply the switch texture to it.
2) Use the Entity Tool (Shift+E) to insert an env_texturetoggle somewhere near the brush. Set the keyvalue Name to "switch_tt" and the keyvalue Target Brush(es) to "switch". Click Apply and close the properties window.

Example:
news post image

3) Select the brush and tie it to an entity (CTRL+T), then choose func_button from the Class drop down list.
4) Set the keyvalue Name to "switch", and if you want the keyvalue Sounds to Lightswitch. Click Apply. On the Flags tab check Don't move, Toggle and Use Activates.
5) On the Outputs tab add two OnPressed outputs, one that points to the input IncrementTextureIndex of your env_texturetoggle ("switch_tt" ) and one that points to the input Toggle of a light (in my case called "light" ) or to whatever you want the switch to control.

Example:
news post image

Finally, click Apply and close the properties window. Now compile and run your map and enjoy your beautiful lightswitch.

Example:
news post image

news post image

Notes:
-Instead of using IncrementTextureIndex you could use SetTextureIndex to switch to a specific frame of the texture, useful in my example of the television screen: You could make a remote control with a few buttons, each button pointing to another frame ("channel" ).
-In this case there's a func_button that switches its own texture via an env_texturetoggle, but it's also possible to let a func_button switch a texture on an external entity such as a func_wall via an env_texturetoggle.

There are many more possibilities and many more ideas of using this method. I found it strange there's no good documentation about switchable texture so I hope this tutorial was useful!



NightHawk

View comments ( 13 )

Back to top