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¶
Inherits: Resource < RefCounted < Object
A color transition.
Description¶
This resource describes a color transition by defining a set of colored points and how to interpolate between them.
See also Curve which supports more complex easing methods, but does not support colors.
Properties¶
|
||
|
||
|
||
|
Methods¶
void |
|
get_offset ( int point ) |
|
get_point_count ( ) const |
|
void |
remove_point ( int point ) |
void |
reverse ( ) |
void |
|
void |
set_offset ( int point, float offset ) |
Enumerations¶
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 色彩空间。该色彩空间能够在不同颜色之间进行平滑、外观统一的过渡。
Property Descriptions¶
PackedColorArray colors = PackedColorArray(0, 0, 0, 1, 1, 1, 1, 1)
void set_colors ( PackedColorArray value )
PackedColorArray get_colors ( )
PackedColorArray 形式的渐变色颜色。
注意:这个属性返回的是副本,修改返回值并不会对渐变色进行更新。要更新渐变色,请使用 set_color 方法(单独更新颜色)或直接为这个属性赋值(一次性更新所有颜色)。
ColorSpace interpolation_color_space = 0
void set_interpolation_color_space ( ColorSpace value )
ColorSpace get_interpolation_color_space ( )
用于在渐变点之间进行插值的色彩空间。不影响返回的颜色,返回的颜色始终在 sRGB 空间。可用的模式见 ColorSpace。
注意:interpolation_mode 为 GRADIENT_INTERPOLATE_CONSTANT 时该设置无效。
InterpolationMode interpolation_mode = 0
void set_interpolation_mode ( InterpolationMode value )
InterpolationMode get_interpolation_mode ( )
用于在渐变点之间进行插值的算法。可用的模式见 InterpolationMode。
PackedFloat32Array offsets = PackedFloat32Array(0, 1)
void set_offsets ( PackedFloat32Array value )
PackedFloat32Array get_offsets ( )
PackedFloat32Array 形式的渐变色偏移。
注意:这个属性返回的是副本,修改返回值并不会对渐变色进行更新。要更新渐变色,请使用 set_offset 方法(单独更新偏移)或直接为这个属性赋值(一次性更新所有偏移)。
Method Descriptions¶
void add_point ( float offset, Color color )
Adds the specified color to the gradient, with the specified offset.
返回渐变色在索引 point
处的颜色。
float get_offset ( int point )
返回渐变色在索引 point
处的偏移。
int get_point_count ( ) const
返回渐变中的颜色数。
void remove_point ( int point )
Removes the color at index point
.
void reverse ( )
将渐变进行翻转/镜像。
注意:这个方法会将所有点以渐变的中点进行镜像,interpolation_mode 为 GRADIENT_INTERPOLATE_CONSTANT 时可能产生意外的结果。
返回由偏移 offset
指定的插值颜色。
void set_color ( int point, Color color )
设置渐变色在索引 point
处的颜色。
void set_offset ( int point, float offset )
设置渐变色