LSL HUD Tutorial

By Xah Lee. Date: .

HUD stands for Heads-Up Display. They are used for graphical user interface elements, such as menu, power-meters, buttons.

HUD Are Just Objects

In Second Life, a HUD is simply a normal object (prims) that are attached to the user's “screen”. So, all scripting about prims applies to the HUD system. There is nothing special about objects used as a HUD.

Here are some examples of HUDs as seen from a user's screen:

C:SI HUD
A “c:si” sword fighting system HUD. Note that there are several buttons, 2 bar-meters, and info as floating texts.
tech war hud
A “Tech Warfare” game HUD. The round things are buttons, and the green bar is a health meter.
golf HUD
A golf game HUD. The circles are buttons, and the big circle in the middle is a round-shaped meter.
2 HUDs rezed on the ground. From this view, we can clearly see that, HUDs are just made of prims. In the case of the Combat Samurai Island hud, it is made up with several prims with transparent textures.

A button in a hud, is simply a prim that responds to touch. A bar meter in a hud, is simply a long box prim that changes its length, or changes it's texture. A round meter in a hud, is just a rotating prim. How a hud responds to the environment/game is simply scritped by the normal ways of communication. For example, in a gun fighting game, if a player is hit, the bullet may broadcast a message, and the hud's health bar prim will listen to it, and decrease its length.

HUD Attachment Points

There are 8 positions on the screen for hud attachment. They are: Center 2, Top Right, Top, Top Left, Center, Bottom Left, Bottom, Bottom Right.

How is A Prim's Dimension Mapped To The Screen

A object has 3 dimensions, x, y, and z. The screen has only 2 dimensions. When a prim is attached to the screen, its size in x dimension is ignored. Its y dimension is the width of the object on the screen, and its z dimension is the height.

The user's Second Life window height determines how many pixels is 1 meter. So, if your Second Life window is 1024 pixels vertically, then, 1 meter = 1024 pixels. This means, if you attach a cube prim .5 meter per side, to the center of the screen, then it will have a height of 512 pixels. (and width of 512 pixels too)

Screen's Coordinate System

A object attached to the screen can be moved vertically or horizontally. This is done by right click on the object, then drag the arrows the same way you change object's positions in-world.