ServersYour serverFor creatorsForumFAQDocumentationSecurity
Download the launcher
  1. Documentation
  2. Client functions
  3. dxDrawRectangle

Function

dxDrawRectangle

Draws a filled rectangle on the screen for one frame. Call it in onClientRender to keep it visible.

Syntax

bool dxDrawRectangle(float startX, float startY, float width, float height [, int color = tocolor(255, 255, 255), bool postGUI = false])

Arguments

startXfloat
Left edge in pixels.
startYfloat
Top edge in pixels.
widthfloat
Width.
heightfloat
Height.
colorint, optional = tocolor(255, 255, 255)
Colour from tocolor.
postGUIbool, optional = false
true = above GUI windows.

Differences from MTA:SA

  • These MTA:SA arguments are not here: bool subPixelPositioning = false

In MTA:SA

dxDrawRectangle(float startX, float startY, float width, float height, int color = white, bool postGUI = false, bool subPixelPositioning = false)

Returns

true if drawn.

Example

A health bar in the bottom-left corner.

local sw, sh = guiGetScreenSize()
addEventHandler("onClientRender", root, function()
    local hp = getElementHealth(localPlayer)
    dxDrawRectangle(30, sh - 60, 204, 18, tocolor(0, 0, 0, 160))
    dxDrawRectangle(32, sh - 58, 2 * hp, 14, tocolor(200, 40, 40))
end)

See also