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.

Gradient

繼承: Resource < RefCounted < Object

顏色過渡。

說明

此資源透過定義一組彩色點以及如何在它們之間進行內插來描述顏色過渡。

另請參見 Curve,它支援更複雜的緩動方法,但不支援顏色。

屬性

PackedColorArray

colors

PackedColorArray(0, 0, 0, 1, 1, 1, 1, 1)

ColorSpace

interpolation_color_space

0

InterpolationMode

interpolation_mode

0

PackedFloat32Array

offsets

PackedFloat32Array(0, 1)

方法

void

add_point(offset: float, color: Color)

Color

get_color(point: int)

float

get_offset(point: int)

int

get_point_count() const

void

remove_point(point: int)

void

reverse()

Color

sample(offset: float)

void

set_color(point: int, color: Color)

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) 🔗

Gradient's colors as a PackedColorArray.

Note: Setting this property updates all colors at once. To update any color individually use 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 🔗

The color space used to interpolate between points of the gradient. It does not affect the returned colors, which will always use nonlinear sRGB encoding.

Note: This setting has no effect when interpolation_mode is set to GRADIENT_INTERPOLATE_CONSTANT.


InterpolationMode interpolation_mode = 0 🔗

The algorithm used to interpolate between points of the gradient.


PackedFloat32Array offsets = PackedFloat32Array(0, 1) 🔗

Gradient's offsets as a PackedFloat32Array.

Note: Setting this property updates all offsets at once. To update any offset individually use 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) 🔗

使用指定的偏移,將指定的顏色新增到該漸變的末尾。


Color get_color(point: int) 🔗

返回漸變色在索引 point 處的顏色。


float get_offset(point: int) 🔗

返回漸變色在索引 point 處的偏移。


int get_point_count() const 🔗

返回漸變中的顏色數。


void remove_point(point: int) 🔗

移除索引 point 處的顏色。


void reverse() 🔗

將漸變進行翻轉/鏡像。

注意:這個方法會將所有點以漸變的中點進行鏡像,interpolation_modeGRADIENT_INTERPOLATE_CONSTANT 時可能產生意外的結果。


Color sample(offset: float) 🔗

Returns the interpolated color specified by offset. offset should be between 0.0 and 1.0 (inclusive). Using a value lower than 0.0 will return the same color as 0.0, and using a value higher than 1.0 will return the same color as 1.0. If your input value is not within this range, consider using @GlobalScope.remap() on the input value with output values set to 0.0 and 1.0.


void set_color(point: int, color: Color) 🔗

設定漸變色在索引 point 處的顏色。


void set_offset(point: int, offset: float) 🔗

設定漸變色在索引 point 處的偏移。