# dxDrawText (Client)

> Draws text on the screen for one frame, inside a box.

- **Platform**: MY Multiplayer (MYMP)
- **Kind**: Lua Function
- **Side**: Client
- **Category**: Screen drawing
- **URL**: https://wiki.mymp.gg/en/dxDrawText

## Syntax

```lua
bool dxDrawText(string text, float leftX, topY [, float rightX, bottomY = leftX, topY, color color = tocolor(255, 255, 255), float scaleX, scaleY = 1, string|element font = default, string alignX = left, string alignY = top, bool clip = false, bool wordBreak = false, bool postGUI = false, bool colorCoded = false, bool subPixelPositioning = false, float rotation = 0, float rotationCenterX, rotationCenterY = nil, float lineHeight = 0])
```

## Parameters

| Name | Type | Description |
| --- | --- | --- |
| `text` | `string` | The text, in UTF-8. `\n` breaks the line. |
| `leftX, topY` | `float` | Top-left corner of the box, in pixels. A vec2 also works. |
| `rightX, bottomY` | `float` | Bottom-right corner of the box, in pixels. A vec2 also works. *(default: `leftX, topY`)* |
| `color` | `color` | Colour, a `tocolor` value. *(default: `tocolor(255, 255, 255)`)* |
| `scaleX, scaleY` | `float` | Text scale. One number applies to both axes. A vec2 also works. *(default: `1`)* |
| `font` | `string\|element` | A font's name (from a pack or given to `dxCreateFont`) or a font element from `dxCreateFont`. *(default: `default`)* |
| `alignX` | `string` | Horizontal alignment in the box: `left`, `center` or `right`. *(default: `left`)* |
| `alignY` | `string` | Vertical alignment in the box: `top`, `center` or `bottom`. *(default: `top`)* |
| `clip` | `bool` | Cut what falls outside the box. *(default: `false`)* |
| `wordBreak` | `bool` | Wrap lines that do not fit the box's width. *(default: `false`)* |
| `postGUI` | `bool` | Draw on top of the interface. *(default: `false`)* |
| `colorCoded` | `bool` | Read `#RRGGBB` colour codes inside the text. *(default: `false`)* |
| `subPixelPositioning` | `bool` | Keep fractional positions instead of snapping to whole pixels. *(default: `false`)* |
| `rotation` | `float` | Rotation in degrees. *(default: `0`)* |
| `rotationCenterX, rotationCenterY` | `float` | Centre of the rotation, in pixels. The box's centre by default. *(default: `nil`)* |
| `lineHeight` | `float` | Height of each line in pixels. 0 uses the font's height. *(default: `0`)* |

## Returns

`true` once the drawing is queued, `false` when the font does not exist.

## Example

```lua
local sx, sy = getScreenSize()

addEventHandler("onClientRender", root, function()
    dxDrawText("#FFAA00MYMP #FFFFFFRoleplay", 0, 20, sx, 60, tocolor(255, 255, 255), 2, "default", "center", "top", false, false, false, true)
end)
```

### Note

`lineHeight` only applies to `colorCoded` text; text without colour codes always uses the font's height. A font name that does not exist logs a warning and the function returns `false`.

## See also

- [dxGetTextWidth (Client)](https://wiki.mymp.gg/en/dxGetTextWidth.md): Measures how wide a text is on the screen, at its widest line.
- [dxGetTextSize (Client)](https://wiki.mymp.gg/en/dxGetTextSize.md): Measures the width and height a text takes on the screen.
- [dxCreateFont (Client)](https://wiki.mymp.gg/en/dxCreateFont.md): Creates a font from a font file in the resource, for the text functions.
- [onClientRender (Client)](https://wiki.mymp.gg/en/onClientRender.md): Fired every frame, when that frame's dx drawing should be done.
