Attention: Here be dragons

This is the latest (unstable) version of this documentation, which may document features not available in or compatible with released stable versions of Godot.

DPITexture

实验性: This class may be changed or removed in future versions.

继承: Texture2D < Texture < Resource < RefCounted < Object

可自动缩放的 Texture2D,基于 SVG 图像。

描述

可自动缩放的 Texture2D,基于 SVG 图像。DPITexture 可以对图标及其他基于纹理的 UI 主题元素自动重新进行栅格化,从而匹配视口的缩放和字体过采样设置。另见 ProjectSettings.display/window/stretch/mode(“canvas_items”模式)和 Viewport.oversampling_override

属性

float

base_scale

1.0

Dictionary

color_map

{}

bool

fix_alpha_border

false

bool

premult_alpha

false

bool

resource_local_to_scene

false (overrides Resource)

float

saturation

1.0

方法

DPITexture

create_from_string(source: String, scale: float = 1.0, saturation: float = 1.0, color_map: Dictionary = {}) static

RID

get_scaled_rid() const

String

get_source() const

void

set_size_override(size: Vector2i)

void

set_source(source: String)


属性说明

float base_scale = 1.0 🔗

  • void set_base_scale(value: float)

  • float get_base_scale()

纹理缩放。1.0 是原始 SVG 大小。值越大得到的图像越大。


Dictionary color_map = {} 🔗

设置后,会根据 Color-Color 映射对纹理中的颜色进行重映射。


bool fix_alpha_border = false 🔗

  • void set_fix_alpha_border(value: bool)

  • bool get_fix_alpha_border()

如果设为 true,它会在从透明到不透明的过渡区域,填充周围相同颜色的像素。对于使用双线性过滤(bilinear filtering)显示的纹理,这有助于减少从图像编辑器导出图片时产生的边缘轮廓效应。


bool premult_alpha = false 🔗

  • void set_premult_alpha(value: bool)

  • bool get_premult_alpha()

除了使用 fix_alpha_border 来修复发黑的边缘,另一种替代方案是使用预乘 Alpha(premultiplied alpha)。启用此选项后,纹理会被自动转换成这种格式。不过,预乘 Alpha 纹理需要配合特定的材质才能正确显示:


float saturation = 1.0 🔗

  • void set_saturation(value: float)

  • float get_saturation()

覆盖纹理饱和度。


方法说明

DPITexture create_from_string(source: String, scale: float = 1.0, saturation: float = 1.0, color_map: Dictionary = {}) static 🔗

新建 DPITexture,并通过分配内存并将 SVG 数据设置为 source 来对其进行初始化。


RID get_scaled_rid() const 🔗

返回栅格化后的纹理 RID,与当前绘制的画布项的过采样匹配。


String get_source() const 🔗

返回该 SVG 纹理的源代码。


void set_size_override(size: Vector2i) 🔗

将纹理的大小调整为指定的尺寸。


void set_source(source: String) 🔗

设置该 SVG 纹理的源代码。