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.
Checking the stable version of the documentation...
Gradient
继承: Resource < RefCounted < Object
颜色过渡。
描述
该资源通过定义一组彩色点以及如何在它们之间进行插值来描述颜色过渡。
另见 Curve,它支持更复杂的缓动方法,但不支持颜色。
属性
|
||
|
||
|
||
|
方法
void |
|
get_offset(point: int) |
|
get_point_count() const |
|
void |
remove_point(point: int) |
void |
reverse() |
void |
|
void |
set_offset(point: int, offset: float) |
枚举
enum InterpolationMode: 🔗
InterpolationMode GRADIENT_INTERPOLATE_LINEAR = 0
线性插值。
InterpolationMode GRADIENT_INTERPOLATE_CONSTANT = 1
常量插值,颜色会在每个点上突变,在点和点之间保持一致。在某些情况下用于渐变纹理时,可能会造成明显的锯齿。
InterpolationMode GRADIENT_INTERPOLATE_CUBIC = 2
三次插值。
enum ColorSpace: 🔗
ColorSpace GRADIENT_COLOR_SPACE_SRGB = 0
sRGB 色彩空间。
ColorSpace GRADIENT_COLOR_SPACE_LINEAR_SRGB = 1
线性 sRGB 色彩空间。
ColorSpace GRADIENT_COLOR_SPACE_OKLAB = 2
Oklab 色彩空间。该色彩空间能够在不同颜色之间进行平滑、外观统一的过渡。
属性说明
PackedColorArray colors = PackedColorArray(0, 0, 0, 1, 1, 1, 1, 1)
🔗
void set_colors(value: PackedColorArray)
PackedColorArray get_colors()
渐变的颜色,类型为 PackedColorArray。
注意:设置该属性会一次性更新所有颜色。单独更改某个颜色请使用 set_color()。
Note: The returned array is copied and any changes to it will not update the original property value. See PackedColorArray for more details.
ColorSpace interpolation_color_space = 0
🔗
void set_interpolation_color_space(value: ColorSpace)
ColorSpace get_interpolation_color_space()
用于在渐变点之间进行插值的色彩空间。不影响返回的颜色,返回的颜色始终在 sRGB 空间。可用的模式见 ColorSpace。
注意:interpolation_mode 为 GRADIENT_INTERPOLATE_CONSTANT 时该设置无效。
InterpolationMode interpolation_mode = 0
🔗
void set_interpolation_mode(value: InterpolationMode)
InterpolationMode get_interpolation_mode()
用于在渐变点之间进行插值的算法。可用的模式见 InterpolationMode。
PackedFloat32Array offsets = PackedFloat32Array(0, 1)
🔗
void set_offsets(value: PackedFloat32Array)
PackedFloat32Array get_offsets()
渐变的偏移量,类型为 PackedFloat32Array。
注意:设置该属性会一次性更新所有偏移量。单独更改某个偏移量请使用 set_offset()。
Note: The returned array is copied and any changes to it will not update the original property value. See PackedFloat32Array for more details.
方法说明
void add_point(offset: float, color: Color) 🔗
使用指定的偏移,将指定的颜色添加到该渐变中。
返回渐变色在索引 point
处的颜色。
float get_offset(point: int) 🔗
返回渐变色在索引 point
处的偏移。
返回渐变中的颜色数。
void remove_point(point: int) 🔗
移除索引 point
处的颜色。
void reverse() 🔗
将渐变进行翻转/镜像。
注意:这个方法会将所有点以渐变的中点进行镜像,interpolation_mode 为 GRADIENT_INTERPOLATE_CONSTANT 时可能产生意外的结果。
返回由偏移 offset
指定的插值颜色。
void set_color(point: int, color: Color) 🔗
设置渐变色在索引 point
处的颜色。
void set_offset(point: int, offset: float) 🔗
设置渐变色在索引 point
处的偏移。