Up to date

This page is up to date for Godot 4.2. If you still find outdated information, please open an issue.

TextMesh

继承: PrimitiveMesh < Mesh < Resource < RefCounted < Object

从文本生成 PrimitiveMesh

描述

根据文本生成 PrimitiveMesh

使用了矢量字形轮廓的动态字体才能用于生成 TextMesh。不支持位图字体(包括 TrueType/OpenType 容器中的位图数据,例如彩色 Emoji 字体)。

UV 布局由 4 个横条组成,从上到下依次为:正面占 40% 高度,背面占 40% 的高度,外面占 10% 的高度,内侧面占 10% 的高度。

教程

属性

AutowrapMode

autowrap_mode

0

float

curve_step

0.5

float

depth

0.05

Font

font

int

font_size

16

HorizontalAlignment

horizontal_alignment

1

BitField<JustificationFlag>

justification_flags

163

String

language

""

float

line_spacing

0.0

Vector2

offset

Vector2(0, 0)

float

pixel_size

0.01

StructuredTextParser

structured_text_bidi_override

0

Array

structured_text_bidi_override_options

[]

String

text

""

Direction

text_direction

0

bool

uppercase

false

VerticalAlignment

vertical_alignment

1

float

width

500.0


属性说明

AutowrapMode autowrap_mode = 0

如果设置为 TextServer.AUTOWRAP_OFF 以外的值,则文本将在节点的边界矩形内自动换行。如果你调整节点大小,就会自动更改其高度,从而显示所有文本。要了解每种模式的行为方式,请参阅 AutowrapMode


float curve_step = 0.5

  • void set_curve_step ( float value )

  • float get_curve_step ( )

用于近似贝塞尔曲线的步长(单位为像素)。


float depth = 0.05

  • void set_depth ( float value )

  • float get_depth ( )

生成的网格的深度,设为 0.0 时只有正面,此时的 UV 布局会变为让正面占据整张纹理。


Font font

  • void set_font ( Font value )

  • Font get_font ( )

用于显示文本的字体配置。


int font_size = 16

  • void set_font_size ( int value )

  • int get_font_size ( )

TextMesh 文本的字体大小。


HorizontalAlignment horizontal_alignment = 1

控制文本的水平对齐方式。支持左对齐、居中对齐、右对齐、和填充、或两端对齐。将其设置为 HorizontalAlignment 常量之一。


BitField<JustificationFlag> justification_flags = 163

行两端对齐规则。详见 JustificationFlag


String language = ""

  • void set_language ( String value )

  • String get_language ( )

语言代码,用于文本塑形算法,如果留空则使用当前区域设置。


float line_spacing = 0.0

  • void set_line_spacing ( float value )

  • float get_line_spacing ( )

多行 TextMesh 中,行与行之间的垂直间距。


Vector2 offset = Vector2(0, 0)

文本绘制偏移(单位为像素)。


float pixel_size = 0.01

  • void set_pixel_size ( float value )

  • float get_pixel_size ( )

文本上一个像素宽度的大小,以 3D 缩放。


StructuredTextParser structured_text_bidi_override = 0

为结构化文本设置 BiDi 算法覆盖。


Array structured_text_bidi_override_options = []

  • void set_structured_text_bidi_override_options ( Array value )

  • Array get_structured_text_bidi_override_options ( )

设置 BiDi 覆盖的附加选项。


String text = ""

用于生成网格的文本。


Direction text_direction = 0

基础文本书写方向。


bool uppercase = false

  • void set_uppercase ( bool value )

  • bool is_uppercase ( )

如果为 true,所有文本都将显示为大写。


VerticalAlignment vertical_alignment = 1

控制文本的垂直对齐方式。支持顶部对齐、居中对齐、底部对齐。请将其设置为 VerticalAlignment 常量。


float width = 500.0

  • void set_width ( float value )

  • float get_width ( )

文本宽度(单位为像素),用于填充对齐。