Skip to content

TextTexture

自 2.2.1

TextTexture 将翻译后的字符串渲染为 GUI 纹理。它支持多种显示模式(居中、左对齐、滚动、悬停显示)、自动换行、背景色以及可选的实时更新供应器。

注册名:text_texture

INFO

继承自 TransformTexture — 支持 rotate()scale()transform()


用法

java
// Static centred text
IGuiTexture label = new TextTexture("Hello World");

// Left-aligned, coloured, with shadow
IGuiTexture info = new TextTexture("Info", 0xFFFFDD44)
    .setType(TextTexture.TextType.LEFT)
    .setDropShadow(true);

// Scrolling text, word-wrap at 80 px
IGuiTexture scroll = new TextTexture("Long description that scrolls…")
    .setType(TextTexture.TextType.ROLL_ALWAYS)
    .setWidth(80)
    .setRollSpeed(1.5f);

// Dynamic — updates every game tick
IGuiTexture dynamic = new TextTexture(() -> "Ticks: " + level.getGameTime());

文本类型

类型对齐方式溢出行为
NORMAL居中所有行堆叠显示。
LEFT左对齐所有行堆叠显示。
RIGHT右对齐所有行堆叠显示。
HIDE居中显示第一行;悬停时完整文本滚动显示。
LEFT_HIDE左对齐显示第一行;悬停时完整文本滚动显示。
ROLL居中显示第一行;悬停且文本溢出时滚动。
LEFT_ROLL左对齐显示第一行;悬停时滚动。
ROLL_ALWAYS居中始终滚动,无论是否悬停。
LEFT_ROLL_ALWAYS左对齐始终滚动,无论是否悬停。

字段

名称类型描述
textString显示的字符串(通过 LocalizationUtils 翻译)。
colorint文本颜色(ARGB)。默认值:-1(白色)。
backgroundColorint背景填充颜色。0 = 无。
widthint自动换行的最大行宽(像素)。
rollSpeedfloat滚动模式的滚动速度。默认值:1.0
dropShadowboolean是否绘制阴影。默认值:false(使用 String 的构造函数会设为 true)。
typeTextType显示模式。默认值:NORMAL
supplierSupplier<String>(可空)设置后,text 每游戏刻从此供应器更新。

方法

方法返回值描述
setColor(int)TextTexture设置文本颜色。
setBackgroundColor(int)TextTexture设置背景填充颜色。
setDropShadow(boolean)TextTexture启用或禁用阴影。
setWidth(int)TextTexture设置换行宽度并重排行。
setType(TextType)TextTexture设置显示模式。
setRollSpeed(float)TextTexture设置滚动模式的滚动速度。
setSupplier(Supplier<String>)TextTexture注册每刻更新的实时文本供应器。
updateText(String)void立即更新文本并重排行。
copy()TextTexture返回深拷贝。

Released under the MIT License.