GpuParticles2D
A 2D particle emitter.
A 2D particle emitter.
2D particle node used to create a variety of particle systems and effects. GpuParticles2D features an emitter that generates some number of particles at a given rate.
Use the GpuParticles2D.ProcessMaterial property to add a ParticleProcessMaterial to configure particle appearance and behavior. Alternatively, you can add a ShaderMaterial which will be applied to all particles.
2D particles can optionally collide with LightOccluder2D, but they don't collide with PhysicsBody2D nodes.
Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.
Constructors1
GpuParticles2DConstructor
public GpuParticles2D();Properties26
AmountProperty
public int Amount { get; set; }The number of particles to emit in one emission cycle. The effective emission rate is (amount * amount_ratio) / lifetime particles per second. Higher values will increase GPU requirements, even if not all particles are visible at a given time or if GpuParticles2D.AmountRatio is decreased.
Note: Changing this value will cause the particle system to restart. To avoid this, change GpuParticles2D.AmountRatio instead.
AmountRatioProperty
public float AmountRatio { get; set; }The ratio of particles that should actually be emitted. If set to a value lower than 1.0, this will set the amount of emitted particles throughout the lifetime to amount * amount_ratio. Unlike changing GpuParticles2D.Amount, changing GpuParticles2D.AmountRatio while emitting does not affect already-emitted particles and doesn't cause the particle system to restart. GpuParticles2D.AmountRatio can be used to create effects that make the number of emitted particles vary over time.
Note: Reducing the GpuParticles2D.AmountRatio has no performance benefit, since resources need to be allocated and processed for the total GpuParticles2D.Amount of particles regardless of the GpuParticles2D.AmountRatio. If you don't intend to change the number of particles emitted while the particles are emitting, make sure GpuParticles2D.AmountRatio is set to 1 and change GpuParticles2D.Amount to your liking instead.
CollisionBaseSizeProperty
public float CollisionBaseSize { get; set; }Multiplier for particle's collision radius. 1.0 corresponds to the size of the sprite. If particles appear to sink into the ground when colliding, increase this value. If particles appear to float when colliding, decrease this value. Only effective if ParticleProcessMaterial.CollisionMode is ParticleProcessMaterial.CollisionModeEnum.Rigid or ParticleProcessMaterial.CollisionModeEnum.HideOnContact.
Note: Particles always have a spherical collision shape.
DrawOrderProperty
public GpuParticles2D.DrawOrderEnum DrawOrder { get; set; }Particle draw order.
EmittingProperty
public bool Emitting { get; set; }Allows new particles to be emitted. false does not delete existing live particles; they remain until their lifetimes end. This is not a full pause or Restart. For OneShot, observe Finished rather than treating Emitting=false as proof that the screen is empty.
ExplosivenessProperty
public float Explosiveness { get; set; }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.
FixedFpsProperty
public int FixedFps { get; set; }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.
FractDeltaProperty
public bool FractDelta { get; set; }If true, results in fractional delta calculation which has a smoother particles display effect.
InterpToEndProperty
public float InterpToEnd { get; set; }Causes all the particles in this node to interpolate towards the end of their lifetime.
Note: This only works when used with a ParticleProcessMaterial. It needs to be manually implemented for custom process shaders.
InterpolateProperty
public bool Interpolate { get; set; }Enables particle interpolation, which makes the particle movement smoother when their GpuParticles2D.FixedFps is lower than the screen refresh rate.
LifetimeProperty
public double Lifetime { get; set; }The amount of time each particle will exist (in seconds). The effective emission rate is (amount * amount_ratio) / lifetime particles per second.
LocalCoordsProperty
public bool LocalCoords { get; set; }Selects simulation space. With true, previously emitted particles follow emitter transforms; with false, they remain in world canvas space when the emitter subsequently moves. Choose before starting the effect and account for visibility bounds separately.
OneShotProperty
public bool OneShot { get; set; }If true, only one emission cycle occurs. If set true during a cycle, emission will stop at the cycle's end.
PreprocessProperty
public double Preprocess { get; set; }Particle system starts as if it had already run for this many seconds.
Note: This can be very expensive if set to a high number as it requires running the particle shader a number of times equal to the GpuParticles2D.FixedFps (or 30, if GpuParticles2D.FixedFps is 0) for every second. In extreme cases it can even lead to a GPU crash due to the volume of work done in a single frame.
ProcessMaterialProperty
public Material ProcessMaterial { get; set; }Simulation material, such as ParticleProcessMaterial or ShaderMaterial with a particle shader; separate from the CanvasItem drawing material. Assigning a ParticleProcessMaterial with DisableZ off and default gravity (0,-9.8,0) enables DisableZ and changes gravity to (0,98,0). This also edits a shared resource. Set intended 2D parameters explicitly before assignment.
RandomnessProperty
public float Randomness { get; set; }Emission lifetime randomness ratio.
SeedProperty
public uint Seed { get; set; }Sets the random seed used by the particle system. Only effective if GpuParticles2D.UseFixedSeed is true.
SpeedScaleProperty
public double SpeedScale { get; set; }Particle system's running speed scaling ratio. A value of 0 can be used to pause the particles.
SubEmitterProperty
public EntityPath SubEmitter { get; set; }Path to another GpuParticles2D node that will be used as a subemitter (see ParticleProcessMaterial.SubEmitterMode). Subemitters can be used to achieve effects such as fireworks, sparks on collision, bubbles popping into water drops, and more.
Note: When GpuParticles2D.SubEmitter is set, the target GpuParticles2D node will no longer emit particles on its own.
TextureProperty
public Texture2D Texture { get; set; }Particle texture. If null, particles will be squares with a size of 1×1 pixels.
Note: To use a flipbook texture, assign a new CanvasItemMaterial to the GpuParticles2D's CanvasItem.Material property, then enable CanvasItemMaterial.ParticlesAnimation and set CanvasItemMaterial.ParticlesAnimHFrames, CanvasItemMaterial.ParticlesAnimVFrames, and CanvasItemMaterial.ParticlesAnimLoop to match the flipbook texture.
TrailEnabledProperty
public bool TrailEnabled { get; set; }If true, enables particle trails using a mesh skinning system.
Note: Unlike GpuParticles3D, the number of trail sections and subdivisions is set with the GpuParticles2D.TrailSections and GpuParticles2D.TrailSectionSubdivisions properties.
TrailLifetimeProperty
public double TrailLifetime { get; set; }The amount of time the particle's trail should represent (in seconds). Only effective if GpuParticles2D.TrailEnabled is true.
TrailSectionSubdivisionsProperty
public int TrailSectionSubdivisions { get; set; }The number of subdivisions to use for the particle trail rendering. Higher values can result in smoother trail curves, at the cost of performance due to increased mesh complexity. See also GpuParticles2D.TrailSections. Only effective if GpuParticles2D.TrailEnabled is true.
TrailSectionsProperty
public int TrailSections { get; set; }The number of sections to use for the particle trail rendering. Higher values can result in smoother trail curves, at the cost of performance due to increased mesh complexity. See also GpuParticles2D.TrailSectionSubdivisions. Only effective if GpuParticles2D.TrailEnabled is true.
UseFixedSeedProperty
public bool UseFixedSeed { get; set; }If true, particles will use the same seed for every simulation using the seed defined in GpuParticles2D.Seed. This is useful for situations where the visual outcome should be consistent across replays, for example when using Movie Maker mode.
VisibilityRectProperty
public Rect2 VisibilityRect { get; set; }Configured GPU-effect visibility bounds. Used for culling; not a trajectory, physics boundary or per-particle clipping rectangle. Allow for full lifetime, texture size and emitter motion. The verified Compatibility CaptureRect fails for 2D, so the example supplies conservative bounds explicitly.
Methods59
CaptureRectRect2
public Rect2 CaptureRect();Requests current particle bounds from the renderer. In the verified 1.0.0 Compatibility/OpenGL build, the 2D call reproduced buffer-read errors and an empty Rect2. Do not treat this result as proof of no particles or as a reliable source for VisibilityRect.
Explicit bounds for the complete example.
Rect2Renderer-provided Rect2. In the reproduced OpenGL failure it is empty despite visible particles. This call was not verified on other backends.
ConvertFromParticlesvoid
public void ConvertFromParticles(Entity particles);Sets this node's properties to match a given CpuParticles2D node.
| Name | Type | Default |
|---|---|---|
particles | Entity | — |
EmitParticlevoid
public void EmitParticle(Transform2D xform, Vector2 velocity, Color color, Color custom, uint flags);Emits a single particle. Whether xform, velocity, color and custom are applied depends on the value of flags. See GpuParticles2D.EmitFlags.
The default ParticleProcessMaterial needs to have ParticleProcessMaterial.ParticleFlagPreserveColor set to true to correctly use the color given from this function.
Additionally, it will use the contents of custom as (rotation, lifetime, animation, lifetime randomness).
Note: GpuParticles2D.EmitParticle is only supported on the Forward+ and Mobile rendering methods, not Compatibility.
| Name | Type | Default |
|---|---|---|
xform | Transform2D | — |
velocity | Vector2 | — |
color | Color | — |
custom | Color | — |
flags | uint | — |
GetAmountint
public int GetAmount();intGetAmountRatiofloat
public float GetAmountRatio();floatGetCollisionBaseSizefloat
public float GetCollisionBaseSize();floatGetDrawOrderGpuParticles2D.DrawOrderEnum
public GpuParticles2D.DrawOrderEnum GetDrawOrder();GpuParticles2D.DrawOrderEnumGetExplosivenessRatiofloat
public float GetExplosivenessRatio();floatGetFixedFpsint
public int GetFixedFps();intGetFractionalDeltabool
public bool GetFractionalDelta();boolGetInterpToEndfloat
public float GetInterpToEnd();floatGetInterpolatebool
public bool GetInterpolate();boolGetLifetimedouble
public double GetLifetime();doubleGetOneShotbool
public bool GetOneShot();boolGetPreProcessTimedouble
public double GetPreProcessTime();doubleGetProcessMaterialMaterial
public Material GetProcessMaterial();MaterialGetRandomnessRatiofloat
public float GetRandomnessRatio();floatGetSeeduint
public uint GetSeed();uintGetSpeedScaledouble
public double GetSpeedScale();doubleGetSubEmitterEntityPath
public EntityPath GetSubEmitter();EntityPathGetTextureTexture2D
public Texture2D GetTexture();Texture2DGetTrailLifetimedouble
public double GetTrailLifetime();doubleGetTrailSectionSubdivisionsint
public int GetTrailSectionSubdivisions();intGetTrailSectionsint
public int GetTrailSections();intGetUseFixedSeedbool
public bool GetUseFixedSeed();boolGetUseLocalCoordinatesbool
public bool GetUseLocalCoordinates();boolGetVisibilityRectRect2
public Rect2 GetVisibilityRect();Rect2IsEmittingbool
public bool IsEmitting();boolIsTrailEnabledbool
public bool IsTrailEnabled();boolRequestParticlesProcess2 overloads
public void RequestParticlesProcess(float processTime);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 GpuParticles2D.SpeedScale set to 0.0, this is useful to be able to seek a particle system timeline.
| Name | Type | Default |
|---|---|---|
processTime | float | — |
public void RequestParticlesProcess(float processTime, float processTimeResidual = 0f);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 GpuParticles2D.SpeedScale set to 0.0, this is useful to be able to seek a particle system timeline.
| Name | Type | Default |
|---|---|---|
processTime | float | — |
processTimeResidual | float | 0f |
Restart2 overloads
public void Restart();Restarts the particle system. Use Restart(bool keepSeed) for explicit seed control. Restart differs from merely setting Emitting=true and begins the effect again.
public void Restart(bool keepSeed = false);Resets simulation state and enables emission. Seed is retained when keepSeed=true or UseFixedSeed=true; a new random value is selected only when both are false. The image changes after processing/rendering a frame.
| Name | Type | Default |
|---|---|---|
keepSeed | bool | false |
keepSeedtrue retains the current seed. false does not force a new seed when UseFixedSeed is already true. Keeping a seed does not guarantee identical pixels across CPU/GPU implementations, devices or configurations.
SetAmountvoid
public void SetAmount(int amount);| Name | Type | Default |
|---|---|---|
amount | int | — |
SetAmountRatiovoid
public void SetAmountRatio(float ratio);| Name | Type | Default |
|---|---|---|
ratio | float | — |
SetCollisionBaseSizevoid
public void SetCollisionBaseSize(float size);| Name | Type | Default |
|---|---|---|
size | float | — |
SetDrawOrdervoid
public void SetDrawOrder(GpuParticles2D.DrawOrderEnum order);| Name | Type | Default |
|---|---|---|
order | GpuParticles2D.DrawOrderEnum | — |
SetEmittingvoid
public void SetEmitting(bool emitting);| Name | Type | Default |
|---|---|---|
emitting | bool | — |
SetExplosivenessRatiovoid
public void SetExplosivenessRatio(float ratio);| Name | Type | Default |
|---|---|---|
ratio | float | — |
SetFixedFpsvoid
public void SetFixedFps(int fps);| Name | Type | Default |
|---|---|---|
fps | int | — |
SetFractionalDeltavoid
public void SetFractionalDelta(bool enable);| Name | Type | Default |
|---|---|---|
enable | bool | — |
SetInterpToEndvoid
public void SetInterpToEnd(float interp);| Name | Type | Default |
|---|---|---|
interp | float | — |
SetInterpolatevoid
public void SetInterpolate(bool enable);| Name | Type | Default |
|---|---|---|
enable | bool | — |
SetLifetimevoid
public void SetLifetime(double secs);| Name | Type | Default |
|---|---|---|
secs | double | — |
SetOneShotvoid
public void SetOneShot(bool secs);| Name | Type | Default |
|---|---|---|
secs | bool | — |
SetPreProcessTimevoid
public void SetPreProcessTime(double secs);| Name | Type | Default |
|---|---|---|
secs | double | — |
SetProcessMaterialvoid
public void SetProcessMaterial(Material material);| Name | Type | Default |
|---|---|---|
material | Material | — |
SetRandomnessRatiovoid
public void SetRandomnessRatio(float ratio);| Name | Type | Default |
|---|---|---|
ratio | float | — |
SetSeedvoid
public void SetSeed(uint seed);| Name | Type | Default |
|---|---|---|
seed | uint | — |
SetSpeedScalevoid
public void SetSpeedScale(double scale);| Name | Type | Default |
|---|---|---|
scale | double | — |
SetSubEmittervoid
public void SetSubEmitter(EntityPath path);| Name | Type | Default |
|---|---|---|
path | EntityPath | — |
SetTexturevoid
public void SetTexture(Texture2D texture);| Name | Type | Default |
|---|---|---|
texture | Texture2D | — |
SetTrailEnabledvoid
public void SetTrailEnabled(bool enabled);| Name | Type | Default |
|---|---|---|
enabled | bool | — |
SetTrailLifetimevoid
public void SetTrailLifetime(double secs);| Name | Type | Default |
|---|---|---|
secs | double | — |
SetTrailSectionSubdivisionsvoid
public void SetTrailSectionSubdivisions(int subdivisions);| Name | Type | Default |
|---|---|---|
subdivisions | int | — |
SetTrailSectionsvoid
public void SetTrailSections(int sections);| Name | Type | Default |
|---|---|---|
sections | int | — |
SetUseFixedSeedvoid
public void SetUseFixedSeed(bool useFixedSeed);| Name | Type | Default |
|---|---|---|
useFixedSeed | bool | — |
SetUseLocalCoordinatesvoid
public void SetUseLocalCoordinates(bool enable);| Name | Type | Default |
|---|---|---|
enable | bool | — |
SetVisibilityRectvoid
public void SetVisibilityRect(Rect2 visibilityRect);| Name | Type | Default |
|---|---|---|
visibilityRect | Rect2 | — |
Signals and events1
FinishedEvent
public event Action Finished;Emitted when all active particles have finished processing. To immediately restart the emission cycle, call GpuParticles2D.Restart.
This signal is never emitted when GpuParticles2D.OneShot is disabled, as particles will be emitted and processed continuously.
Note: For GpuParticles2D.OneShot emitters, due to the particles being computed on the GPU, there may be a short period after receiving the signal during which setting GpuParticles2D.Emitting to true will not restart the emission cycle. This delay is avoided by instead calling GpuParticles2D.Restart.
GpuParticles2D.DrawOrderEnum
| Value | Description |
|---|---|
Index = 0 | Particles are drawn in the order emitted. |
Lifetime = 1 | Particles are drawn in order of remaining lifetime. In other words, the particle with the highest lifetime is drawn at the front. |
ReverseLifetime = 2 | Particles are drawn in reverse order of remaining lifetime. In other words, the particle with the lowest lifetime is drawn at the front. |
GpuParticles2D.EmitFlags
| Value | Description |
|---|---|
Color = 8 | Particle starts with specified color. |
Custom = 16 | Particle starts with specified |
Position = 1 | Particle starts at the specified position. |
RotationScale = 2 | Particle starts with specified rotation and scale. |
Velocity = 4 | Particle starts with the specified velocity vector, which defines the emission direction and speed. |