Crosshair

From ZDoom Wiki
(Redirected from Crosshairs)
Jump to navigation Jump to search
DoomWiki.org
For more information on this article, visit the crosshairs page on the Doom Wiki.

The crosshair or crosshairs is a small graphics displayed as part of the HUD in the center of the screen and serving as a targeting aid.

ZDoom provides a selection of seven crosshairs, which can be configured through the HUD options menu. Additional crosshairs can be given through a custom XHAIRS lump. Weapons can feature their own built-in crosshairs with the A_SetCrosshair function.

The user's choice of crosshair is stored in the crosshair variable. A value of 0 means "no crosshair", and a positive value refers to that crosshair number.

Creating your own crosshairs

Creating crosshairs is a simple process:

  1. Create a crosshair graphic. You can use a PNG image with an alpha channel, or a grayscale image where white is opaque and black is transparent.
  2. Name the graphic XHAIRB## where ## is a crosshair number starting with 1, such as XHAIRB25. (Note that GZDoom itself occupies the first 7 crosshairs, so use larger numbers if you don't want to override them.)
  3. Place the graphic under the /graphics/ folder of your PK3 archive.
  4. (Optional) Add a small version of your crosshair and name it XHAIRS## where ## is the same number, such as XHAIRS25. This version will only be used at very low resolutions, so nowadays it's arguably not necessary.
  5. Offset the crosshair graphic in SLADE in "Sprite" mode so it's exactly at the center. (For example, if your graphic is 64x64 pixels, the offsets must be set to 32, 32). (Note, it may seem like crosshairs provided in gzdoom.pk3 are not offset, but this is because they are in .imgz format, which stores offsets differently from .png, and SLADE simply cannot display it.)
  6. If you want your crosshair to be selectable in the in-game options menu, you also need to define it in the XHAIRS lump:
25 "My custom crosshair"

The crosshair can be changed by the player with the crosshair CVAR (e.g. crosshair 25 will select crosshair No. 25). If the crosshair has been added to the XHAIRS lump, its name will also show up in the options menu.

The crosshair can also be set from ZScript or DECORATE with A_SetCrosshair (for example, if you want the crosshair to change for a specific weapon or attack sequence).