CPUParticles2D
Inherits: Entity2D < CanvasItem < Entity < Object
Description
Section titled “Description”A CPU-based 2D particle emitter.
CPU-based 2D particle node used to create a variety of particle systems and effects.
See also GPUParticles2D, which provides the same functionality with hardware acceleration, but may not run on older devices.
Properties
Section titled “Properties”Methods
Section titled “Methods”| Returns | Method |
|---|---|
| void | convert_from_particles(particles: Entity) |
| 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) |
Signals
Section titled “Signals”finished
finished()
Emitted when all active particles have finished processing. When one_shot is disabled, particles will process continuously, so this is never emitted.
Enumerations
Section titled “Enumerations”DrawOrder
enum DrawOrder
DRAW_ORDER_INDEX = 0
Particles are drawn in the order emitted.
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.
Parameter
enum Parameter
PARAM_INITIAL_LINEAR_VELOCITY = 0
Use with set_param_min(), set_param_max(), and set_param_curve() to set initial velocity properties.
PARAM_ANGULAR_VELOCITY = 1
Use with set_param_min(), set_param_max(), and set_param_curve() to set angular velocity properties.
PARAM_ORBIT_VELOCITY = 2
Use with set_param_min(), set_param_max(), and set_param_curve() to set orbital velocity properties.
PARAM_LINEAR_ACCEL = 3
Use with set_param_min(), set_param_max(), and set_param_curve() to set linear acceleration properties.
PARAM_RADIAL_ACCEL = 4
Use with set_param_min(), set_param_max(), and set_param_curve() to set radial acceleration properties.
PARAM_TANGENTIAL_ACCEL = 5
Use with set_param_min(), set_param_max(), and set_param_curve() to set tangential acceleration properties.
PARAM_DAMPING = 6
Use with set_param_min(), set_param_max(), and set_param_curve() to set damping properties.
PARAM_ANGLE = 7
Use with set_param_min(), set_param_max(), and set_param_curve() to set angle properties.
PARAM_SCALE = 8
Use with set_param_min(), set_param_max(), and set_param_curve() to set scale properties.
PARAM_HUE_VARIATION = 9
Use with set_param_min(), set_param_max(), and set_param_curve() to set hue variation properties.
PARAM_ANIM_SPEED = 10
Use with set_param_min(), set_param_max(), and set_param_curve() to set animation speed properties.
PARAM_ANIM_OFFSET = 11
Use with set_param_min(), set_param_max(), and set_param_curve() to set animation offset properties.
PARAM_MAX = 12
Represents the size of the Parameter enum.
ParticleFlags
enum ParticleFlags
PARTICLE_FLAG_ALIGN_Y_TO_VELOCITY = 0
Use with set_particle_flag() to set particle_flag_align_y.
PARTICLE_FLAG_ROTATE_Y = 1
Present for consistency with 3D particle nodes, not used in 2D.
PARTICLE_FLAG_DISABLE_Z = 2
Present for consistency with 3D particle nodes, not used in 2D.
PARTICLE_FLAG_MAX = 3
Represents the size of the ParticleFlags enum.
EmissionShape
enum EmissionShape
EMISSION_SHAPE_POINT = 0
All particles will be emitted from a single point.
EMISSION_SHAPE_SPHERE = 1
Particles will be emitted in the volume of a sphere flattened to two dimensions.
EMISSION_SHAPE_SPHERE_SURFACE = 2
Particles will be emitted on the surface of a sphere flattened to two dimensions.
EMISSION_SHAPE_RECTANGLE = 3
Particles will be emitted in the area of a rectangle.
EMISSION_SHAPE_POINTS = 4
Particles will be emitted at a position chosen randomly among emission_points. Particle color will be modulated by emission_colors.
EMISSION_SHAPE_DIRECTED_POINTS = 5
Particles will be emitted at a position chosen randomly among emission_points. Particle velocity and rotation will be set based on emission_normals. Particle color will be modulated by emission_colors.
EMISSION_SHAPE_RING = 6
Particles will be emitted in the area of a ring parameterized by its outer and inner radius.
EMISSION_SHAPE_MAX = 7
Represents the size of the EmissionShape enum.
Property descriptions
Section titled “Property descriptions”amount
int amount = 8
Number of particles emitted in one emission cycle.
angle_curve
Curve angle_curve
Each particle’s rotation will be animated along this Curve. Should be a unit Curve.
angle_max
float angle_max = 0.0
Maximum initial rotation applied to each particle, in degrees.
angle_min
float angle_min = 0.0
Minimum equivalent of angle_max.
angular_velocity_curve
Curve angular_velocity_curve
Each particle’s angular velocity will vary along this Curve. Should be a unit Curve.
angular_velocity_max
float angular_velocity_max = 0.0
Maximum initial angular velocity (rotation speed) applied to each particle in degrees per second.
angular_velocity_min
float angular_velocity_min = 0.0
Minimum equivalent of angular_velocity_max.
anim_offset_curve
Curve anim_offset_curve
Each particle’s animation offset will vary along this Curve. Should be a unit Curve.
anim_offset_max
float anim_offset_max = 0.0
Maximum animation offset that corresponds to frame index in the texture. 0 is the first frame, 1 is the last one. See CanvasItemMaterial.particles_animation.
anim_offset_min
float anim_offset_min = 0.0
Minimum equivalent of anim_offset_max.
anim_speed_curve
Curve anim_speed_curve
Each particle’s animation speed will vary along this Curve. Should be a unit Curve.
anim_speed_max
float anim_speed_max = 0.0
Maximum particle animation speed. Animation speed of 1 means that the particles will make full 0 to 1 offset cycle during lifetime, 2 means 2 cycles etc.
With animation speed greater than 1, remember to enable CanvasItemMaterial.particles_anim_loop property if you want the animation to repeat.
anim_speed_min
float anim_speed_min = 0.0
Minimum equivalent of anim_speed_max.
color
Color color = Color(1, 1, 1, 1)
Each particle’s initial color. If texture is defined, it will be multiplied by this color.
color_initial_ramp
Gradient color_initial_ramp
Each particle’s initial color will vary along this Gradient (multiplied with color).
color_ramp
Gradient color_ramp
Each particle’s color will vary along this Gradient over its lifetime (multiplied with color).
damping_curve
Curve damping_curve
Damping will vary along this Curve. Should be a unit Curve.
damping_max
float damping_max = 0.0
The maximum rate at which particles lose velocity. For example value of 100 means that the particle will go from 100 velocity to 0 in 1 second.
damping_min
float damping_min = 0.0
Minimum equivalent of damping_max.
direction
Vector2 direction = Vector2(1, 0)
Unit vector specifying the particles’ emission direction.
draw_order
DrawOrder draw_order = 0
Particle draw order.
emission_colors
PackedColorArray emission_colors
Sets the Colors to modulate particles by when using EMISSION_SHAPE_POINTS or EMISSION_SHAPE_DIRECTED_POINTS.
emission_normals
PackedVector2Array emission_normals
Sets the direction the particles will be emitted in when using EMISSION_SHAPE_DIRECTED_POINTS.
emission_points
PackedVector2Array emission_points
Sets the initial positions to spawn particles when using EMISSION_SHAPE_POINTS or EMISSION_SHAPE_DIRECTED_POINTS.
emission_rect_extents
Vector2 emission_rect_extents
The rectangle’s extents if emission_shape is set to EMISSION_SHAPE_RECTANGLE.
emission_ring_inner_radius
float emission_ring_inner_radius
The ring’s inner radius if emission_shape is set to EMISSION_SHAPE_RING.
emission_ring_radius
float emission_ring_radius
The ring’s outer radius if emission_shape is set to EMISSION_SHAPE_RING.
emission_shape
EmissionShape emission_shape = 0
Particles will be emitted inside this region.
emission_sphere_radius
float emission_sphere_radius
The sphere’s radius if emission_shape is set to EMISSION_SHAPE_SPHERE.
emitting
bool emitting = true
If true, particles are being emitted. emitting can be used to start and stop particles from emitting. However, if one_shot is true setting emitting to true will not restart the emission cycle until after all active particles finish processing. You can use the finished signal to be notified once all active particles finish processing.
explosiveness
float explosiveness = 0.0
How rapidly particles in an emission cycle are emitted. If greater than 0, there will be a gap in emissions before the next cycle begins.
fixed_fps
int fixed_fps = 0
The particle system’s frame rate is fixed to a value. For example, changing the value to 2 will make the particles render at 2 frames per second. Note this does not slow down the simulation of the particle system itself.
fract_delta
bool fract_delta = true
If true, results in fractional delta calculation which has a smoother particles display effect.
gravity
Vector2 gravity = Vector2(0, 980)
Gravity applied to every particle.
hue_variation_curve
Curve hue_variation_curve
Each particle’s hue will vary along this Curve. Should be a unit Curve.
hue_variation_max
float hue_variation_max = 0.0
Maximum initial hue variation applied to each particle. It will shift the particle color’s hue.
hue_variation_min
float hue_variation_min = 0.0
Minimum equivalent of hue_variation_max.
initial_velocity_max
float initial_velocity_max = 0.0
Maximum initial velocity magnitude for each particle. Direction comes from direction and spread.
initial_velocity_min
float initial_velocity_min = 0.0
Minimum equivalent of initial_velocity_max.
lifetime
float lifetime = 1.0
Amount of time each particle will exist.
lifetime_randomness
float lifetime_randomness = 0.0
Particle lifetime randomness ratio.
linear_accel_curve
Curve linear_accel_curve
Each particle’s linear acceleration will vary along this Curve. Should be a unit Curve.
linear_accel_max
float linear_accel_max = 0.0
Maximum linear acceleration applied to each particle in the direction of motion.
linear_accel_min
float linear_accel_min = 0.0
Minimum equivalent of linear_accel_max.
local_coords
bool local_coords = false
If true, particles use the parent node’s coordinate space (known as local coordinates). This will cause particles to move and rotate along the CPUParticles2D node (and its parents) when it is moved or rotated. If false, particles use global coordinates; they will not move or rotate along the CPUParticles2D node (and its parents) when it is moved or rotated.
one_shot
bool one_shot = false
If true, only one emission cycle occurs. If set true during a cycle, emission will stop at the cycle’s end.
orbit_velocity_curve
Curve orbit_velocity_curve
Each particle’s orbital velocity will vary along this Curve. Should be a unit Curve.
orbit_velocity_max
float orbit_velocity_max = 0.0
Maximum orbital velocity applied to each particle. Makes the particles circle around origin. Specified in number of full rotations around origin per second.
orbit_velocity_min
float orbit_velocity_min = 0.0
Minimum equivalent of orbit_velocity_max.
particle_flag_align_y
bool particle_flag_align_y = false
Align Y axis of particle with the direction of its velocity.
preprocess
float preprocess = 0.0
Particle system starts as if it had already run for this many seconds.
radial_accel_curve
Curve radial_accel_curve
Each particle’s radial acceleration will vary along this Curve. Should be a unit Curve.
radial_accel_max
float radial_accel_max = 0.0
Maximum radial acceleration applied to each particle. Makes particle accelerate away from the origin or towards it if negative.
radial_accel_min
float radial_accel_min = 0.0
Minimum equivalent of radial_accel_max.
randomness
float randomness = 0.0
Emission lifetime randomness ratio.
scale_amount_curve
Curve scale_amount_curve
Each particle’s scale will vary along this Curve. Should be a unit Curve.
scale_amount_max
float scale_amount_max = 1.0
Maximum initial scale applied to each particle.
scale_amount_min
float scale_amount_min = 1.0
Minimum equivalent of scale_amount_max.
scale_curve_x
Curve scale_curve_x
Each particle’s horizontal scale will vary along this Curve. Should be a unit Curve.
split_scale must be enabled.
scale_curve_y
Curve scale_curve_y
Each particle’s vertical scale will vary along this Curve. Should be a unit Curve.
split_scale must be enabled.
seed
int seed = 0
Sets the random seed used by the particle system. Only effective if use_fixed_seed is true.
speed_scale
float speed_scale = 1.0
Particle system’s running speed scaling ratio. A value of 0 can be used to pause the particles.
split_scale
bool split_scale = false
If true, the scale curve will be split into x and y components. See scale_curve_x and scale_curve_y.
spread
float spread = 45.0
Each particle’s initial direction range from +spread to -spread degrees.
tangential_accel_curve
Curve tangential_accel_curve
Each particle’s tangential acceleration will vary along this Curve. Should be a unit Curve.
tangential_accel_max
float tangential_accel_max = 0.0
Maximum tangential acceleration applied to each particle. Tangential acceleration is perpendicular to the particle’s velocity giving the particles a swirling motion.
tangential_accel_min
float tangential_accel_min = 0.0
Minimum equivalent of tangential_accel_max.
texture
Texture2D texture
Particle texture. If null, particles will be squares.
use_fixed_seed
bool use_fixed_seed = false
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.
Method descriptions
Section titled “Method descriptions”convert_from_particles
void convert_from_particles(particles: Entity)
Sets this node’s properties to match a given GPUParticles2D node with an assigned ParticleProcessMaterial.
get_param_curve
Curve get_param_curve(param: Parameter) const
Returns the Curve of the parameter specified by Parameter.
get_param_max
float get_param_max(param: Parameter) const
Returns the maximum value range for the given parameter.
get_param_min
float get_param_min(param: Parameter) const
Returns the minimum value range for the given parameter.
get_particle_flag
bool get_particle_flag(particle_flag: ParticleFlags) const
Returns the enabled state of the given particle flag.
request_particles_process
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.
restart
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.
set_param_curve
void set_param_curve(param: Parameter, curve: Curve)
Sets the Curve of the parameter specified by Parameter. Should be a unit Curve.
set_param_max
void set_param_max(param: Parameter, value: float)
Sets the maximum value for the given parameter.
set_param_min
void set_param_min(param: Parameter, value: float)
Sets the minimum value for the given parameter.
set_particle_flag
void set_particle_flag(particle_flag: ParticleFlags, enable: bool)
Enables or disables the given particle flag.
