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.

CPUParticles2D

繼承: Node2D < CanvasItem < Node < Object

基於 CPU 的 2D 粒子發射器。

說明

基於 CPU 的 2D 粒子節點,可用於建立各種粒子系統、粒子效果。

另見 GPUParticles2D,利用硬體加速提供了相同的功能,但可能無法在較舊的裝置上運作。

教學

屬性

int

amount

8

Curve

angle_curve

float

angle_max

0.0

float

angle_min

0.0

Curve

angular_velocity_curve

float

angular_velocity_max

0.0

float

angular_velocity_min

0.0

Curve

anim_offset_curve

float

anim_offset_max

0.0

float

anim_offset_min

0.0

Curve

anim_speed_curve

float

anim_speed_max

0.0

float

anim_speed_min

0.0

Color

color

Color(1, 1, 1, 1)

Gradient

color_initial_ramp

Gradient

color_ramp

Curve

damping_curve

float

damping_max

0.0

float

damping_min

0.0

Vector2

direction

Vector2(1, 0)

DrawOrder

draw_order

0

PackedColorArray

emission_colors

PackedVector2Array

emission_normals

PackedVector2Array

emission_points

Vector2

emission_rect_extents

float

emission_ring_inner_radius

float

emission_ring_radius

EmissionShape

emission_shape

0

float

emission_sphere_radius

bool

emitting

true

float

explosiveness

0.0

int

fixed_fps

0

bool

fract_delta

true

Vector2

gravity

Vector2(0, 980)

Curve

hue_variation_curve

float

hue_variation_max

0.0

float

hue_variation_min

0.0

float

initial_velocity_max

0.0

float

initial_velocity_min

0.0

float

lifetime

1.0

float

lifetime_randomness

0.0

Curve

linear_accel_curve

float

linear_accel_max

0.0

float

linear_accel_min

0.0

bool

local_coords

false

bool

one_shot

false

Curve

orbit_velocity_curve

float

orbit_velocity_max

0.0

float

orbit_velocity_min

0.0

bool

particle_flag_align_y

false

PhysicsInterpolationMode

physics_interpolation_mode

2 (overrides Node)

float

preprocess

0.0

Curve

radial_accel_curve

float

radial_accel_max

0.0

float

radial_accel_min

0.0

float

randomness

0.0

Curve

scale_amount_curve

float

scale_amount_max

1.0

float

scale_amount_min

1.0

Curve

scale_curve_x

Curve

scale_curve_y

int

seed

0

float

speed_scale

1.0

bool

split_scale

false

float

spread

45.0

Curve

tangential_accel_curve

float

tangential_accel_max

0.0

float

tangential_accel_min

0.0

Texture2D

texture

bool

use_fixed_seed

false

方法

void

convert_from_particles(particles: Node)

Curve

get_param_curve(param: Parameter) const

float

get_param_max(param: Parameter) const

float

get_param_min(param: Parameter) const

bool

get_particle_flag(particle_flag: ParticleFlags) const

void

request_particles_process(process_time: float, process_time_residual: float = 0.0)

void

restart(keep_seed: bool = false)

void

set_param_curve(param: Parameter, curve: Curve)

void

set_param_max(param: Parameter, value: float)

void

set_param_min(param: Parameter, value: float)

void

set_particle_flag(particle_flag: ParticleFlags, enable: bool)


訊號

finished() 🔗

所有活動粒子完成處理時發出。當 one_shot 停用時,粒子將連續處理,因此永遠不會發出。


列舉

enum DrawOrder: 🔗

DrawOrder DRAW_ORDER_INDEX = 0

粒子按發射順序繪製。

DrawOrder DRAW_ORDER_LIFETIME = 1

Particles are drawn in order of remaining lifetime. In other words, the particle with the highest lifetime is drawn at the front.


enum Parameter: 🔗

Parameter PARAM_INITIAL_LINEAR_VELOCITY = 0

set_param_min()set_param_max()set_param_curve() 一起使用,設定初始速度屬性。

Parameter PARAM_ANGULAR_VELOCITY = 1

set_param_min()set_param_max()set_param_curve() 一起使用,設定角速度屬性。

Parameter PARAM_ORBIT_VELOCITY = 2

set_param_min()set_param_max()set_param_curve() 一起使用,設定軌道速度屬性。

Parameter PARAM_LINEAR_ACCEL = 3

set_param_min()set_param_max()set_param_curve() 一起使用,設定線性加速度屬性。

Parameter PARAM_RADIAL_ACCEL = 4

set_param_min()set_param_max()set_param_curve() 一起使用,設定徑向加速度屬性。

Parameter PARAM_TANGENTIAL_ACCEL = 5

set_param_min()set_param_max()set_param_curve() 一起使用,設定切向加速度屬性。

Parameter PARAM_DAMPING = 6

set_param_min()set_param_max()set_param_curve() 一起使用,設定阻尼屬性。

Parameter PARAM_ANGLE = 7

set_param_min()set_param_max()set_param_curve() 一起使用,設定角度屬性。

Parameter PARAM_SCALE = 8

set_param_min()set_param_max()set_param_curve() 一起使用,設定縮放屬性。

Parameter PARAM_HUE_VARIATION = 9

set_param_min()set_param_max()set_param_curve() 一起使用,設定色相變化屬性。

Parameter PARAM_ANIM_SPEED = 10

set_param_min()set_param_max()set_param_curve() 一起使用,設定動畫速度屬性。

Parameter PARAM_ANIM_OFFSET = 11

set_param_min()set_param_max()set_param_curve() 一起使用,設定動畫偏移屬性。

Parameter PARAM_MAX = 12

代表 Parameter 列舉的大小。


enum ParticleFlags: 🔗

ParticleFlags PARTICLE_FLAG_ALIGN_Y_TO_VELOCITY = 0

set_particle_flag() 一起使用,設定 particle_flag_align_y

ParticleFlags PARTICLE_FLAG_ROTATE_Y = 1

為了與 3D 粒子節點保持一致而存在,在 2D 中不被使用。

ParticleFlags PARTICLE_FLAG_DISABLE_Z = 2

為了與 3D 粒子節點保持一致而存在,在 2D 中不被使用。

ParticleFlags PARTICLE_FLAG_MAX = 3

代表 ParticleFlags 列舉的大小。


enum EmissionShape: 🔗

EmissionShape EMISSION_SHAPE_POINT = 0

所有粒子將從單個點發射。

EmissionShape EMISSION_SHAPE_SPHERE = 1

粒子將在扁平化到二維的球體內發射。

EmissionShape EMISSION_SHAPE_SPHERE_SURFACE = 2

粒子將在扁平化到二維的球面上發射。

EmissionShape EMISSION_SHAPE_RECTANGLE = 3

粒子將在矩形區域內發射。

EmissionShape EMISSION_SHAPE_POINTS = 4

粒子將在 emission_points 中隨機選擇的位置發射。粒子顏色將通過 emission_colors 進行調變。

EmissionShape EMISSION_SHAPE_DIRECTED_POINTS = 5

粒子將在 emission_points 中隨機選擇的位置發射。粒子的速度和旋轉將基於 emission_normals 進行設定。粒子顏色將通過 emission_colors 進行調變。

EmissionShape EMISSION_SHAPE_RING = 6

Particles will be emitted in the area of a ring parameterized by its outer and inner radius.

EmissionShape EMISSION_SHAPE_MAX = 7

代表 EmissionShape 列舉的大小。


屬性說明

int amount = 8 🔗

  • void set_amount(value: int)

  • int get_amount()

單個發射週期內發射的粒子數。


Curve angle_curve 🔗

Each particle's rotation will be animated along this Curve. Should be a unit Curve.


float angle_max = 0.0 🔗

套用於每個粒子的最大初始旋轉,單位:度。


float angle_min = 0.0 🔗

angle_max 的對應最小值。


Curve angular_velocity_curve 🔗

Each particle's angular velocity will vary along this Curve. Should be a unit Curve.


float angular_velocity_max = 0.0 🔗

套用於每個粒子的最大初始角速度(旋轉速度),單位:每秒。


float angular_velocity_min = 0.0 🔗

angular_velocity_max 的對應最小值。


Curve anim_offset_curve 🔗

Each particle's animation offset will vary along this Curve. Should be a unit Curve.


float anim_offset_max = 0.0 🔗

與紋理中的影格索引相對應的最大動畫偏移量。0 是第一影格,1 是最後一影格。參見 CanvasItemMaterial.particles_animation


float anim_offset_min = 0.0 🔗

anim_offset_max 的對應最小值。


Curve anim_speed_curve 🔗

Each particle's animation speed will vary along this Curve. Should be a unit Curve.


float anim_speed_max = 0.0 🔗

最大粒子動畫速度。1 的動畫速度是指粒子在生命週期內會做完整的 01 的偏移迴圈,2 則表示 2 個迴圈,如此等等。

當動畫速度大於 1 時,如果希望動畫重複,請記住啟用 CanvasItemMaterial.particles_anim_loop 屬性。


float anim_speed_min = 0.0 🔗

anim_speed_max 的對應最小值。


Color color = Color(1, 1, 1, 1) 🔗

每個粒子的初始顏色。如果定義了 texture,它將乘以該顏色。


Gradient color_initial_ramp 🔗

  • void set_color_initial_ramp(value: Gradient)

  • Gradient get_color_initial_ramp()

Each particle's initial color will vary along this Gradient (multiplied with color).


Gradient color_ramp 🔗

Each particle's color will vary along this Gradient over its lifetime (multiplied with color).


Curve damping_curve 🔗

Damping will vary along this Curve. Should be a unit Curve.


float damping_max = 0.0 🔗

粒子失去速度的最大速率。例如 100 的值表示粒子將在 1 秒內,速度從 100 變為 0


float damping_min = 0.0 🔗

damping_max 的對應最小值。


Vector2 direction = Vector2(1, 0) 🔗

指定粒子發射方向的單位向量。


DrawOrder draw_order = 0 🔗

Particle draw order.


PackedColorArray emission_colors 🔗

設定使用 EMISSION_SHAPE_POINTSEMISSION_SHAPE_DIRECTED_POINTS 時對粒子進行調變的 Color

Note: The returned array is copied and any changes to it will not update the original property value. See PackedColorArray for more details.


PackedVector2Array emission_normals 🔗

設定使用 EMISSION_SHAPE_DIRECTED_POINTS 時粒子發射的方向。

Note: The returned array is copied and any changes to it will not update the original property value. See PackedVector2Array for more details.


PackedVector2Array emission_points 🔗

設定使用 EMISSION_SHAPE_POINTSEMISSION_SHAPE_DIRECTED_POINTS 時出生粒子的初始位置。

Note: The returned array is copied and any changes to it will not update the original property value. See PackedVector2Array for more details.


Vector2 emission_rect_extents 🔗

  • void set_emission_rect_extents(value: Vector2)

  • Vector2 get_emission_rect_extents()

emission_shape 被設定為 EMISSION_SHAPE_RECTANGLE 時,該矩形的範圍。


float emission_ring_inner_radius 🔗

  • void set_emission_ring_inner_radius(value: float)

  • float get_emission_ring_inner_radius()

The ring's inner radius if emission_shape is set to EMISSION_SHAPE_RING.


float emission_ring_radius 🔗

  • void set_emission_ring_radius(value: float)

  • float get_emission_ring_radius()

The ring's outer radius if emission_shape is set to EMISSION_SHAPE_RING.


EmissionShape emission_shape = 0 🔗

Particles will be emitted inside this region.


float emission_sphere_radius 🔗

  • void set_emission_sphere_radius(value: float)

  • float get_emission_sphere_radius()

emission_shape 被設定為 EMISSION_SHAPE_SPHERE 時,該球體的半徑。


bool emitting = true 🔗

  • void set_emitting(value: bool)

  • bool is_emitting()

如果 true,則正在發射粒子。emitting 可用於啟動和停止粒子發射。但是,如果 one_shottrue `` 將\ :ref:`emitting<class_CPUParticles2D_property_emitting>` 設為\ ``true 直到所有活動粒子完成處理後才會重新啟動發射週期。一旦所有活動粒子都完成,您可以使用finished 訊號來通知粒子完成處理。


float explosiveness = 0.0 🔗

  • void set_explosiveness_ratio(value: float)

  • float get_explosiveness_ratio()

粒子在單個發射週期中的發射有多急。如果大於 0,則在下一個發射週期開始之前,發射會出現一個間隔。


int fixed_fps = 0 🔗

  • void set_fixed_fps(value: int)

  • int get_fixed_fps()

粒子系統的畫面播放速率被固定為一個值。例如,將值更改為 2 會使粒子以每秒 2 影格的速度算繪。請注意,這並不會降低粒子系統本身的類比速度。


bool fract_delta = true 🔗

  • void set_fractional_delta(value: bool)

  • bool get_fractional_delta()

如果為 為true,則使用分數差異量 delta 計算,將具有更平滑的粒子顯示效果。


Vector2 gravity = Vector2(0, 980) 🔗

套用於每個粒子的重力。


Curve hue_variation_curve 🔗

Each particle's hue will vary along this Curve. Should be a unit Curve.


float hue_variation_max = 0.0 🔗

套用於每個粒子的最大初始色相變化。會改變粒子顏色的色相。


float hue_variation_min = 0.0 🔗

hue_variation_max 的對應最小值。


float initial_velocity_max = 0.0 🔗

每個粒子的最大初始速度大小。方向來自 directionspread


float initial_velocity_min = 0.0 🔗

initial_velocity_max 的對應最小值。


float lifetime = 1.0 🔗

  • void set_lifetime(value: float)

  • float get_lifetime()

每個粒子存在的時間。


float lifetime_randomness = 0.0 🔗

  • void set_lifetime_randomness(value: float)

  • float get_lifetime_randomness()

粒子壽命隨機率。


Curve linear_accel_curve 🔗

Each particle's linear acceleration will vary along this Curve. Should be a unit Curve.


float linear_accel_max = 0.0 🔗

在運動方向上套用於每個粒子的最大線性加速度。


float linear_accel_min = 0.0 🔗

linear_accel_max 的對應最小值。


bool local_coords = false 🔗

  • void set_use_local_coordinates(value: bool)

  • bool get_use_local_coordinates()

如果為 true,粒子使用父節點的座標空間(稱為局部座標)。這將導致粒子在移動或旋轉時,沿著 CPUParticles2D 節點(及其父節點)移動和旋轉。如果為 false,則粒子使用全域座標;當移動或旋轉時,它們不會沿著 CPUParticles2D 節點(及其父節點)移動或旋轉。


bool one_shot = false 🔗

  • void set_one_shot(value: bool)

  • bool get_one_shot()

如果為 true,則只發生一個發射週期。如果在某個週期內設定為 true,則發射將在該週期結束時停止。


Curve orbit_velocity_curve 🔗

Each particle's orbital velocity will vary along this Curve. Should be a unit Curve.


float orbit_velocity_max = 0.0 🔗

套用於每個粒子的最大軌道速度。使粒子圍繞原點旋轉。以每秒圍繞原點的完整旋轉數指定。


float orbit_velocity_min = 0.0 🔗

orbit_velocity_max 的對應最小值。


bool particle_flag_align_y = false 🔗

將粒子的 Y 軸與其速度方向對齊。


float preprocess = 0.0 🔗

  • void set_pre_process_time(value: float)

  • float get_pre_process_time()

粒子系統啟動時就好像已經運作了這麼多秒一樣。


Curve radial_accel_curve 🔗

Each particle's radial acceleration will vary along this Curve. Should be a unit Curve.


float radial_accel_max = 0.0 🔗

套用於每個粒子的最大徑向加速度。使粒子加速遠離原點;或如果為負,則加速靠近原點。


float radial_accel_min = 0.0 🔗

radial_accel_max 的對應最小值。


float randomness = 0.0 🔗

  • void set_randomness_ratio(value: float)

  • float get_randomness_ratio()

發射壽命隨機率。


Curve scale_amount_curve 🔗

Each particle's scale will vary along this Curve. Should be a unit Curve.


float scale_amount_max = 1.0 🔗

套用於每個粒子的最大初始縮放。


float scale_amount_min = 1.0 🔗

scale_amount_max 的對應最小值。


Curve scale_curve_x 🔗

  • void set_scale_curve_x(value: Curve)

  • Curve get_scale_curve_x()

Each particle's horizontal scale will vary along this Curve. Should be a unit Curve.

split_scale must be enabled.


Curve scale_curve_y 🔗

  • void set_scale_curve_y(value: Curve)

  • Curve get_scale_curve_y()

Each particle's vertical scale will vary along this Curve. Should be a unit Curve.

split_scale must be enabled.


int seed = 0 🔗

  • void set_seed(value: int)

  • int get_seed()

Sets the random seed used by the particle system. Only effective if use_fixed_seed is true.


float speed_scale = 1.0 🔗

  • void set_speed_scale(value: float)

  • float get_speed_scale()

粒子系統的運作速度的縮放率。0 值可用於暫停粒子。


bool split_scale = false 🔗

  • void set_split_scale(value: bool)

  • bool get_split_scale()

如果為 true,縮放曲線將被拆分成 x 和 y 分量。見 scale_curve_xscale_curve_y


float spread = 45.0 🔗

  • void set_spread(value: float)

  • float get_spread()

每個粒子的初始方向範圍,從 +spread 度到 -spread 度。


Curve tangential_accel_curve 🔗

Each particle's tangential acceleration will vary along this Curve. Should be a unit Curve.


float tangential_accel_max = 0.0 🔗

套用於每個粒子的最大切向加速度。切向加速度垂直於粒子的速度,從而使粒子產生渦旋運動。


float tangential_accel_min = 0.0 🔗

tangential_accel_max 的對應最小值。


Texture2D texture 🔗

粒子紋理。如果為 null,則粒子將為正方形。


bool use_fixed_seed = false 🔗

  • void set_use_fixed_seed(value: bool)

  • bool get_use_fixed_seed()

If true, particles will use the same seed for every simulation using the seed defined in seed. This is useful for situations where the visual outcome should be consistent across replays, for example when using Movie Maker mode.


方法說明

void convert_from_particles(particles: Node) 🔗

設定該節點的屬性以配對給定的 GPUParticles2D 節點,該給定節點已分配了一個 ParticleProcessMaterial


Curve get_param_curve(param: Parameter) const 🔗

返回由 Parameter 指定的參數的 Curve


float get_param_max(param: Parameter) const 🔗

返回給定參數的最大值範圍。


float get_param_min(param: Parameter) const 🔗

返回給定參數的最小值範圍。


bool get_particle_flag(particle_flag: ParticleFlags) const 🔗

Returns the enabled state of the given particle flag.


void request_particles_process(process_time: float, process_time_residual: float = 0.0) 🔗

Requests the particles to process for extra process time during a single frame.

process_time defines the time that the particles will process while emitting is on. process_time_residual defines the time that particles will process with emitting turned off for the simulation. When combined with speed_scale set to 0.0, this is useful to be able to seek a particle system timeline.


void restart(keep_seed: bool = false) 🔗

Restarts the particle emitter.

If keep_seed is true, the current random seed will be preserved. Useful for seeking and playback.


void set_param_curve(param: Parameter, curve: Curve) 🔗

Sets the Curve of the parameter specified by Parameter. Should be a unit Curve.


void set_param_max(param: Parameter, value: float) 🔗

設定給定參數的最大值。


void set_param_min(param: Parameter, value: float) 🔗

設定給定參數的最小值。


void set_particle_flag(particle_flag: ParticleFlags, enable: bool) 🔗

Enables or disables the given particle flag.