Skip to content

Commit 10c7a4d

Browse files
committed
Update Working with Text chapter
1 parent c290f40 commit 10c7a4d

File tree

2 files changed

+189
-5
lines changed

2 files changed

+189
-5
lines changed

src/content/docs/ch04/02-basic-messages.mdx

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@ PRINT_HELP_STRING {text} "San Andreas"
4242

4343
Notice that because the text is longer than 8 characters, you need to use double quotes.
4444

45-
## Mission Text
46-
47-
Here is some other message commands and their CLEO counterpart:
45+
## Subtitles
4846

4947
**PRINT_NOW**
5048

@@ -54,6 +52,25 @@ Here is some other message commands and their CLEO counterpart:
5452

5553
<img src="/img/ch-04-02-2.png" alt="PRINT_NOW Example" />
5654

55+
**PRINT**
56+
| Native Command | CLEO Command |
57+
| ----------------------------------------------------- | ------------------------------------------------------- |
58+
| `PRINT {key} 'SAN_AND' {duration} 3000 {style} 1` | `PRINT_STRING {text} "San Andreas" {duration} 3000` |
59+
60+
<img src="/img/ch-04-02-2.png" alt="PRINT_NOW Example" />
61+
62+
`PRINT` has lower priority than `PRINT_NOW`. If there is another message being displayed, the `PRINT` command will wait until the previous message disappears, while `PRINT_NOW` will replace it immediately. You can use this behavior to create a sequence of messages that appear one after another, for example:
63+
64+
```sb
65+
PRINT_STRING {text} "First message" {duration} 3000
66+
PRINT_STRING {text} "Second message" {duration} 3000
67+
PRINT_STRING {text} "Third message" {duration} 3000
68+
```
69+
70+
You can chain up to 8 messages in this way.
71+
72+
## Styled Messages
73+
5774
**PRINT_BIG**
5875

5976
| Native Command | CLEO Command |
Lines changed: 169 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,174 @@
11
---
22
title: Text Draws
3-
description: Text Draws
3+
description: Displaying text at specific screen coordinates
44
slug: text-draws
5+
tableOfContents: true
56
---
67

7-
TBD
8+
Text draws are short text elements displayed at specific coordinates on the screen. Unlike [help boxes](/basic-messages#help-boxes) or [subtitles](/basic-messages#subtitles) that appear at fixed locations, text draws give you full control over where and how the text is rendered. They are commonly used to display information such as player position, debug values, or custom HUD elements.
9+
10+
## How Text Draws Work
11+
12+
The `DISPLAY_TEXT` command shows a GXT text entry at a given position on the screen. The X and Y coordinates are based on a 640 × 448 resolution, which comes from the PS2 version of the games. On different resolutions, these positions are scaled accordingly.
13+
14+
You should always wrap text draw commands with `USE_TEXT_COMMANDS` to prevent unintended side effects like permanent display or game crashes:
15+
16+
```sb
17+
use_text_commands {state} true
18+
display_text {offsetLeft} 200.0 {offsetTop} 100.0 {key} 'MY_TEXT'
19+
use_text_commands {state} false
20+
```
21+
22+
San Andreas supports up to 96 text draws on screen at the same time. Each text must be less than 100 characters long.
23+
24+
:::note
25+
If you're familiar with the concept of [Immediate Mode](https://en.wikipedia.org/wiki/Immediate_mode_GUI) in game development, you'll find that text draws follow a similar pattern. The state is reset after each frame.
26+
:::
27+
28+
## Setup Commands
29+
30+
Before calling `DISPLAY_TEXT`, you can use various setup commands to control how the text looks. These commands affect the next `DISPLAY_TEXT` call only, so you need to set them up each time.
31+
32+
Here is a basic example that displays red text with a custom scale at position (100.0, 50.0):
33+
34+
```sb
35+
use_text_commands {state} true
36+
set_text_colour {red} 255 {green} 0 {blue} 0 {alpha} 255
37+
set_text_scale {widthX} 0.5 {heightY} 1.5
38+
set_text_font {font} 1
39+
display_text {offsetLeft} 100.0 {offsetTop} 50.0 {key} 'DEAD'
40+
use_text_commands {state} false
41+
```
42+
43+
The order of setup commands does not matter, as long as they come before `DISPLAY_TEXT`.
44+
45+
## Color and Scale
46+
47+
`SET_TEXT_COLOUR` sets the text color using RGBA values, where each component ranges from 0 to 255:
48+
49+
```sb
50+
set_text_colour {red} 255 {green} 255 {blue} 0 {alpha} 255
51+
```
52+
53+
Setting alpha to 0 makes the text black.
54+
55+
`SET_TEXT_SCALE` controls the width and height of the text:
56+
57+
```sb
58+
set_text_scale {widthX} 0.48 {heightY} 1.12
59+
```
60+
61+
The default scale in San Andreas is roughly 0.48 × 1.12.
62+
63+
## Alignment
64+
65+
By default, text is left-aligned. You can change the alignment with `SET_TEXT_CENTRE` or `SET_TEXT_RIGHT_JUSTIFY`:
66+
67+
```sb
68+
set_text_centre {state} true
69+
```
70+
71+
```sb
72+
set_text_right_justify {state} true
73+
```
74+
75+
When using center alignment, use `SET_TEXT_CENTRE_SIZE` to set the width of the centered area:
76+
77+
```sb
78+
set_text_centre {state} true
79+
set_text_centre_size {width} 400.0
80+
```
81+
82+
## Text Wrapping
83+
84+
`SET_TEXT_WRAPX` controls where the text wraps to the next line. The value is a screen position (not a width), so a wrap x of `400.0` means the text will wrap when it reaches the `400.0` mark on the screen:
85+
86+
```sb
87+
set_text_wrapx {width} 400.0
88+
```
89+
90+
If your text is being cut off or wrapping too early, adjusting this value is usually the fix.
91+
92+
## Font
93+
94+
`SET_TEXT_FONT` selects which font to use. The available fonts depend on the game:
95+
96+
```sb
97+
set_text_font {font} 2
98+
```
99+
100+
## Background
101+
102+
`SET_TEXT_BACKGROUND` adds a dark rectangle behind the text, making it easier to read over busy scenes:
103+
104+
```sb
105+
set_text_background {state} true
106+
```
107+
108+
## Other Options
109+
110+
`SET_TEXT_PROPORTIONAL` enables proportional character spacing, where each character takes up only as much width as it needs. When disabled, all characters occupy the same width:
111+
112+
```sb
113+
set_text_proportional {state} true
114+
```
115+
116+
`SET_TEXT_DRAW_BEFORE_FADE` controls whether the text draw renders before or after screen fading effects:
117+
118+
```sb
119+
set_text_draw_before_fade {state} true
120+
```
121+
122+
## Displaying Numbers
123+
124+
If you need to display a GXT text that includes numeric placeholders (`~1~`), use `DISPLAY_TEXT_WITH_NUMBER` or `DISPLAY_TEXT_WITH_2_NUMBERS`:
125+
126+
```sb
127+
use_text_commands {state} true
128+
display_text_with_number {offsetLeft} 100.0 {offsetTop} 50.0 {key} 'BJ_0' {number} 42
129+
use_text_commands {state} false
130+
```
131+
132+
```sb
133+
use_text_commands {state} true
134+
display_text_with_2_numbers {offsetLeft} 100.0 {offsetTop} 50.0 {key} 'BJ_OR2' {number1} 10 {number2} 20
135+
use_text_commands {state} false
136+
```
137+
138+
## Putting It All Together
139+
140+
Here is a more complete example that displays a centered, yellow text with a background:
141+
142+
```sb
143+
while true
144+
wait 0
145+
use_text_commands {state} true
146+
set_text_colour {red} 255 {green} 255 {blue} 0 {alpha} 255
147+
set_text_scale {widthX} 0.6 {heightY} 1.5
148+
set_text_font {font} 1
149+
set_text_centre {state} true
150+
set_text_centre_size {width} 500.0
151+
set_text_background {state} true
152+
set_text_proportional {state} true
153+
set_text_draw_before_fade {state} true
154+
display_text {offsetLeft} 320.0 {offsetTop} 200.0 {key} 'MY_TEXT'
155+
use_text_commands {state} false
156+
end
157+
```
158+
159+
## Drawing Text With CLEO 5
160+
161+
CLEO 5 offers a more flexible way to draw text using `DISPLAY_TEXT_FORMATTED`. This command allows you to use any text and format specifiers (like `%d` for integers). This is especially useful for dynamic text that changes based on game variables.
162+
163+
```
164+
while true
165+
wait 0 // draw each frame
166+
use_text_commands {state} true
167+
display_text_formatted {offsetLeft} 50.0 {offsetTop} 100.0 {format} "Simple text"
168+
display_text_formatted {offsetLeft} 50.0 {offsetTop} 200.0 {format} "Timer: %d" {args} TIMERA
169+
end
170+
```
171+
172+
:::tip
173+
For the complete reference of each command and its parameters, visit [the Text class](https://library.sannybuilder.com/#/sa/script/classes/Text) in Sanny Builder Library.
174+
:::

0 commit comments

Comments
 (0)