dxDrawText
Manual Review Required
Please finish this page using the corresponding Old Wiki article. Go to Contribution guidelines for more information.
Draws a string of text on the screen for one frame. In order for the text to stay visible continuously, you need to call this function with the same parameters on each frame update (see onClientRender).
The function is known to optimize certain drawing scenarios related to scaling and opacity (so called text on raster optimisation ). You can find out more about it here .
Syntax
bool dxDrawText ( string text, float leftX, float topY, float textSize, [ float rightX = leftX, float bottomY = topY, int color = white, mixed font = "default", string alignX = "left", string alignY = "top", bool clip = false, bool wordBreak = false, bool postGUI = false, bool colorCoded = false, bool subPixelPositioning = false, float fRotation = 0.0, float fRotationCenterX = 0.0, float fRotationCenterY = 0.0, float fLineSpacing = 0.0 ] )Required Arguments
- text: the text to draw
- leftX: the absolute X coordinate of the top left corner of the text
- topY: the absolute Y coordinate of the top left corner of the text
- textSize: the size of the text scale.
Optional Arguments
NOTE: When using optional arguments, you might need to supply all arguments before the one you wish to use.
- rightX (default: leftX): the absolute X coordinate of the right side of the text bounding box. Used for text aligning, clipping and word breaking.
- bottomY (default: topY): the absolute Y coordinate of the bottom side of the text bounding box. Used for text aligning, clipping and word breaking.
- color (default: white): the color of the text, a value produced by tocolor or 0xAARRGGBB (AA = alpha, RR = red, GG = green, BB = blue).
- font (default: "default"): Either a custom DX font element or the name of a built-in DX font: Note: Some fonts are incompatible with certain languages such as Arabic. "default": Tahoma "default-bold": Tahoma Bold "clear": Verdana "arial": Arial "sans": Microsoft Sans Serif "pricedown": Pricedown (GTA's theme text) "bankgothic": Bank Gothic Medium "diploma": Diploma Regular "beckett": Beckett Regular "unifont": Unifont
- alignX (default: "left"): horizontal alignment of the text within the bounding box. Can be "left" , "center" or "right" .
- alignY (default: "top"): vertical alignment of the text within the bounding box. Can be "top" , "center" or "bottom" .
- clip (default: false): if set to true , the parts of the text that don't fit within the bounding box will be cut off.
- wordBreak (default: false): if set to true , the text will wrap to a new line whenever it reaches the right side of the bounding box. If false , the text will always be completely on one line.
- postGUI (default: false): A bool representing whether the text should be drawn on top of or behind any ingame GUI (rendered by CEGUI).
- colorCoded (default: false): MISSING_PARAM_DESC
- subPixelPositioning (default: false): MISSING_PARAM_DESC
- fRotation (default: 0.0): MISSING_PARAM_DESC
- fRotationCenterX (default: 0.0): MISSING_PARAM_DESC
- fRotationCenterY (default: 0.0): MISSING_PARAM_DESC
- fLineSpacing (default: 0.0): MISSING_PARAM_DESC
Returns
- bool: value
Returns true if successful, false otherwise.
Code Examples
This example code will add the current zone name in the lower left corner of the players' screens.
local screenX, screenY = guiGetScreenSize() -- get the screen resolution (width and height)local shadowColor = tocolor(0, 0, 0, 255) -- define shadow color outside render scope and use it afterwards (for performance reasons)local textColor = tocolor(255, 255, 255, 255) -- define color outside render scope and use it afterwards (for performance reasons)
function renderPlayerZone() local playerX, playerY, playerZ = getElementPosition(localPlayer) -- get our player's coordinates local playerZoneName = getZoneName(playerX, playerY, playerZ) -- get name of the zone the player is in
-- draw zone name text's shadow dxDrawText(playerZoneName, 44, screenY - 41, screenX, screenY, shadowColor, 1.02, "pricedown") -- draw zone name text dxDrawText(playerZoneName, 44, screenY - 43, screenX, screenY, textColor, 1, "pricedown")endaddEventHandler("onClientRender", root, renderPlayerZone)See Also
Drawing Functions
- dxConvertPixels
- dxCreateFont
- dxCreateRenderTarget
- dxCreateScreenSource
- dxCreateShader
- dxCreateTexture
- dxDrawCircle
- dxDrawImage
- dxDrawImageSection
- dxDrawLine
- dxDrawLine3D
- dxDrawMaterialLine3D
- dxDrawMaterialPrimitive
- dxDrawMaterialPrimitive3D
- dxDrawMaterialSectionLine3D
- dxDrawModel3D
- dxDrawPrimitive
- dxDrawPrimitive3D
- dxDrawRectangle
- dxDrawText
- dxDrawWiredSphere
- dxGetBlendMode
- dxGetFontHeight
- dxGetMaterialSize
- dxGetPixelColor
- dxGetPixelsFormat
- dxGetPixelsSize
- dxGetStatus
- dxGetTextSize
- dxGetTexturePixels
- dxGetTextWidth
- dxIsAspectRatioAdjustmentEnabled
- dxSetAspectRatioAdjustmentEnabled
- dxSetBlendMode
- dxSetPixelColor
- dxSetRenderTarget
- dxSetShaderTessellation
- dxSetShaderTransform
- dxSetShaderValue
- dxSetTestMode
- dxSetTextureEdge
- dxSetTexturePixels
- dxUpdateScreenSource