File: text.md

package info (click to toggle)
surgescript 0.5.4.4-1.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,876 kB
  • sloc: ansic: 13,674; makefile: 16
file content (109 lines) | stat: -rw-r--r-- 1,929 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
Text
====

The Text object allows you to display custom texts in the game. The parent object is required to be an [entity](/engine/entity).

Factory
-------

#### Text

`UI.Text(font)`

Spawns a new Text object with the given font name. If `null` is provided as the font name, then a default font will be used.

*Arguments*

* `font`: string. The name of a font (defined in the *fonts/* folder).

*Returns*

A Text object.

*Example*
```
using SurgeEngine.UI.Text;
using SurgeEngine.Transform;
using SurgeEngine.Player;

// Place this on your level to display
// the name of the player
object "PlayerName" is "entity", "awake"
{
    text = Text("GoodNeighbors");
    transform = Transform();

    state "main"
    {
        // position the text
        player = Player.active;
        transform.position = player.transform.position;
        transform.translateBy(0, -50);

        // configure the text
        text.align = "center";
        text.text = player.name;
    }
}
```

Properties
----------

#### text

`text`: string.

The text to be displayed.

#### font

`font`: string, read-only.

The name of the font in use.

#### size

`size`: [Vector2](/engine/vector2) object.

The size, in pixels, of the rendered text.

*Available since:* Open Surge 0.5.1

#### align

`align`: string.

The alignment of the text. One of the following: *"left"*, *"center"*, *"right"*.

#### visible

`visible`: boolean.

Is the Text object visible?

#### maxLength

`maxLength`: number.

The maximum number of characters to be displayed, ignoring *<color>* tags and spaces.

*Available since:* Open Surge 0.5.1

#### maxWidth

`maxWidth`: number.

The maximum width of the text, in pixels. Setting this value will enable wordwrap.

#### zindex

`zindex`: number.

The zindex of the Text object. Defaults to 0.5.

#### offset

`offset`: [Vector2](/engine/vector2) object.

An *(x,y)* offset relative to the parent object. Defaults to zero.