GetScreenWidth

From ZDoom Wiki
Jump to navigation Jump to search


Error.gif
Warning: This feature has at least one use case where the outcome is indeterminate. This feature can break demo and multiplayer sync if an indeterminate result is used to modify the playsim (anything that uses the random number generator, modify level geometry, spawn obstacles, monsters, or powerups, and so on). Usage of the feature in conjunction with non-playsim related features, such as displaying a HudMessage, is safe.

GetScreenWidth only knows the resolution of the local session. Information about the resolution of other players in a game or demo does not exist.

int GetScreenWidth (void)

Usage

Returns the horizontal resolution. For example, if you are playing in 800x600 it will return 800. This is mainly useful for formatting hudmessages which you want to put in the same position on all screens when using SetHudSize.

Return value

The horizontal resolution of the screen.

Examples

This script places an ‘@’ symbol at the left hand side of the screen, 100 pixels from the bottom.

script 1 (void)
{
    int h = GetScreenHeight();
    SetHudSize(GetScreenWidth(), h, 1);
 
    h = (h - 100) << 16;

    HudMessage(s:"@"; HUDMSG_PLAIN, 1,
        CR_BLUE, 0.1, h + 0.1, 10.0);
}

The application of this is that upon building a custom graphic for a HUD, you may want to position info/health/meters/etc. around the edge of the screen according to some positioning system, without necessarily resizing them. See also the command SetFont.

See also