Menu Background Map

From Valve Developer Community
Jump to: navigation, search
English (en)русский (ru)中文 (zh)
Edit

Background maps are the 3D moving backgrounds that appear behind the menus when the game is first launched. They are compiled BSPs, just like standard game maps. Background maps are designed to be used for single player games like Half-Life 2, although any mod can use them. The background map can change as the player unlocks chapters of the game, depending on the author's preferences.

Constructing a Background Map

Background maps should be created like dioramas. The geometry in the map should be strictly limited to only what will be seen in the camera view. The goal is to make the least amount of geometry and materials necessary, so the map is smaller and loads faster.

To create a background map:

  • Create the basic geometry for the scene you want included in the background map. It should not have any leaks, and be sealed like any standard game level. Add lights and materials as needed. You may want to start from an existing level and simply remove or hide geometry and entities that are not needed for the background map. All unnecessary elements should be removed.
  • Add an info_player_logo (Counter-Strike: Source) or info_player_start (singleplayer games) or info_player_teamspawn (Team Fortress 2) to the map. It doesn't much matter where the entity is placed, as long as it is inside the level geometry and not floating so high that the player falls and takes damage.
  • Add a point_viewcontrol entity to the map where you want the camera position to be when the map is displayed. Name the point_viewcontrol something descriptive, (i.e. "viewcontrol_background1" ).
  • For your point_viewcontrol entity, deactivate the flags: Start at Player / Follow Player / Interruptable by Player. Activate the flags: Freeze Player / Infinite Hold Time / Snap to goal angles / Make player non-solid
  • Add an info_target entity. This is the position the point_viewcontrol camera will be pointing at when the map is displayed. Name it similar to the point_viewcontrol ( i.e. "target_background1" ).
  • Select the point_viewcontrol. For the Entity to look at keyvalue, set the value to the info_target you just created as the target entity.
  • The point_viewcontrol must be activated when the background map is loaded. The easiest way to do this is with a logic_auto entity. Add an OnMapSpawn output on the logic_auto that fires the Enable input of the point_viewcontrol.
  • You can add other outputs to the logic_auto for events that you want to happen when the background is displayed, such as lights flickering, NPCs walking by, sounds to play, etc. Be careful about adding too much, however. Background maps should have good performance, load quickly, and not distract too much from the game menus.
  • Save and compile the map just as you would any standard game map. If you're replacing an existing Half-Life 2 map, read Replacing Half-Life 2 background maps below to make sure your map is named properly.

Testing a Background Map

To test a background map, launch the game without loading the map directly. After the engine, bring up the developer console and type:

map_background <mapname>

Where <mapname> is the name of your background map. The map will be loaded and the menu displayed over it.

After testing that the background map works, you can go back and refine it. You may want to add more details, reposition the camera or the camera target. Simply recompile it again and use the map_background command to see your changes. Once the camera position has been finalized, it is also a good idea to optimize the level as much as possible, such as applying the toolsnodraw material to faces that cannot be seen from the camera position. Again, the goal is to make the background map as small as possible, to load and render quickly.

See maps\sdk_background.vmf for an example of a background map.

Menu Background Material

It is also necessary to create background materials for your menu background .BSP. This is the image that is shown when you first launch the game, but before the background .BSP has finished loading. In Half-Life 2, this was a blurred screenshot of the background map (when recreating this, use a 30px Gaussian Blur filter for a 1280x image). When the background .BSP is finished loading, the screen fades from the static background material to the actual 3D background map.

The following two materials are needed:

<game directory>\materials\console\<map name>.vmt

<game directory>\materials\console\<map name>_widescreen.vmt

For example, if you made a background map named sdk_background.bsp, you would need these two materials:

hl2\materials\console\sdk_background.vmt

hl2\materials\console\sdk_background_widescreen.vmt

The background materials are usually a 1024x1024 screenshot of the background map, blurred in an image-editing application.

You can find the key command to take screenshots under Options -> Keyboard when you run the game. The F5 key is the default screenshot key, and saves a .JPG format screen shot to the <game directory>\screenshots directory. You can also bind a key to the screenshot console command, which will save in the .TGA format.

A menu background material .vmt file should look something like this:

UnlitGeneric
{
$basetexture "console/sdk_background"
$vertexcolor 1
$vertexalpha 1
$ignorez 1
$no_fullbright 1
$nolod 1
}

For information on how to create these materials, see the Material Creation doc.

Sample materials for the sdk_background sample map are located in:

\sourcesdk_content\hl2\materialsrc\console (for the source .TGAs)

\half-life 2\hl2\materials\console (for the .VMT and .VTF files).

Script files for background maps and chapters in your own MOD

Once a custom background map has been created, it must be inserted into the proper script files in order for it to be automatically displayed during the correct game chapter.

Note.pngNote:Background maps will not be displayed automatically when your mod is launched with -dev in the launch options.

This section describes the individual files that are used to determine which background map is displayed.

The file hl2\scripts\ChapterBackgrounds.txt associates background maps with particular game chapters. It lists all of the chapters in the game, and which background BSP file will be loaded when that chapter is unlocked by the player's progress.

Here is the ChapterBackgrounds.txt for Half-Life 2:

"chapters"
{
	1	"background01"
	2	"background01"
	3	"background02"
	4	"background02"
	5	"background03"
	6	"background03"
	7	"background04"
	8	"background04"
	9	"background05"
	9a	"background05"
	10	"background06"
	11	"background06"
	12	"background07"
	13	"background07"
}

hl2\scripts\titles.txt contains the chapter key values. A key value is created for each chapter in the game. These key values are put into the “Chapter Title Message” key in the Map Properties (also called worldspawn) under the Map Menu in the Hammer editor. The actual text that shows up for each chapter depends upon the language chosen, in these files:

hl2\resource\hl2_english.txt
hl2\resource\hl2_french.txt
hl2\resource\hl2_german.txt
...

These files contain the actual chapter name text in various languages. The text entered here will be the text that is displayed in-game wherever chapter names appear.

Testing chapterbackgrounds.txt

Once you've made your changes to chapterbackgrounds.txt, you can test your background map using the sv_unlockchapters console variable. This variable control which chapters in the game you have played through, and should be set to the chapter number of the background map you wish to view.

To choose which chapter background to view:

  1. Save your chapterbackgrounds.txt file into the <mod directory>\scripts directory.
  2. Run the game.
  3. Open the developer console.
  4. Type "sv_unlockchapters n" where n is the number of the background in chapterbackgrounds.txt you wish to view.
  5. Type quit to exit the game.
  6. Restart the game, and the chosen menu background should be displayed.
Note.pngNote:The current value of sv_unlockchapters is stored in the config.cfg game settings file, and you can edit this file directly if you wish. For Half-Life 2, this file can be found at \Half-Life 2\hl2\cfg\config.cfg and can be opened in any text editor.

Replacing Half-Life 2 background maps

If you want to replace the background maps built into Half-Life 2 with maps of your own creation, simply create the background .BSP, .VTF and .VMT material files using the above steps, and make the name the map the same as the chapter map you wish to replace. The chapterbackgrounds.txt file (create in /scripts) shows the names of the Half-Life 2 background maps:

"chapters"
{
	1	"background01"
	2	"background01"
	3	"background02"
	4	"background02"
	5	"background03"
	6	"background03"
	7	"background04"
	8	"background04"
	9	"background05"
	9a	"background05"
	10	"background06"
	11	"background06"
	12	"background07"
	13	"background07"
}

For example, if you want to replace first chapter background map, simply name your custom map background01. To replace chapter 10's background map, use background06 as your map name.

Disabling Background Maps

If you would like to just use the vmt texture as a background (without loading a map), simply create the file \cfg\valve.rc and add the following:

// load the base configuration
//exec default.cfg
// Setup custom controller
exec joystick.cfg

// run a user script file if present
exec autoexec.cfg

//
// stuff command line statements
//
stuffcmds

If you'd like to add map loading again, just add the command startupmenu to a new line within the valve.rc file.

If you want your backgrounds to display randomly (like TF2) make sure you have sv_unlockedchapters 99 in either your default config or preferably in your valve.rc file.

Creating chapter backgrounds with XBLAH's Modding Tool

Chapters for single-player games can be created with XBLAH's Modding Tool XBLAH's Modding Tool through an UI. The modder can easily create new chapters, select the chapter images, chapter background images, the first map of the chapter, the background map, and the tool will do the dirty work of creating the required VTFs, VMTs and scripts. It gives the option to automatically blur the background images, so the modder can just take a screenshot of the background map and the tool will apply the usual blur. This replaces the need of saving VTFs, creating chapter images with weird proportions, and so on.


Where to find it
This can be accessed within the tool through Mod > Chapters.


How to use it

You can insert a new chapter by clicking Add button button.

Select a chapter ID (Example 1, 2, 3, or A, B, C, etc) and a chapter title. Right click the picture box next to the Chapter Image label and select a screenshot to show up in the New Menu window. Right click the picture box next to the Chapter Background label and select a screenshot to show up as the menu background (or as the loading screen if a background map is set). Select the map that will load when the user selects that chapter, and, optionally, select a background map.

XBLAH's Modding Tool - Chapters v1.17.0.png

External links