GPUParticles2D
A 2D particle emitter.
GPUParticles2D.swift:27class GPUParticles2D
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 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.
This object emits the following signals:
Superclasses
class Node2D
A 2D game object, inherited by all 2D-related nodes. Has a position, rotation, scale, and Z index.
Citizens in SwiftGodot
Conformances
protocol CustomStringConvertible
A type with a customized textual representation.
protocol Equatable
A type that can be compared for value equality.
protocol Hashable
A type that can be hashed into a
Hasher
to produce an integer hash value.protocol Identifiable<ID>
A class of types whose instances hold the value of an entity with stable identity.
protocol VariantRepresentable
Types that conform to VariantRepresentable can be stored directly in
Variant
with no conversion. These include all of the Variant types from Godot (for exampleGString
,Rect
,Plane
), Godot objects (those that subclass SwiftGodot.Object) as well as the built-in Swift types UInt8, Int64 and Double.protocol VariantStorable
Types that conform to VariantStorable can be stored in a Variant and can be extracted back out of a Variant.
Types
Type members
Instance members
var amount: Int32
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 ifamountRatio
is decreased.var amountRatio: Double
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 toamount * amount_ratio
. Unlike changingamount
, changingamountRatio
while emitting does not affect already-emitted particles and doesn’t cause the particle system to restart.amountRatio
can be used to create effects that make the number of emitted particles vary over time.var collisionBaseSize: Double
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 ifcollisionMode
isParticleProcessMaterial/CollisionMode/collisionRigid
orParticleProcessMaterial/CollisionMode/collisionHideOnContact
.var drawOrder: GPUParticles2D.DrawOrder
Particle draw order. Uses
DrawOrder
values.var emitting: Bool
If
true
, particles are being emitted.emitting
can be used to start and stop particles from emitting. However, ifoneShot
istrue
settingemitting
totrue
will not restart the emission cycle unless all active particles have finished processing. Use the [signal finished] signal to be notified once all active particles finish processing.var explosiveness: Double
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.var finished: SimpleSignal
Emitted when all active particles have finished processing. To immediately restart the emission cycle, call
restart
.var fixedFps: Int32
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.
var fractDelta: Bool
If
true
, results in fractional delta calculation which has a smoother particles display effect.var interpToEnd: Double
Causes all the particles in this node to interpolate towards the end of their lifetime.
var interpolate: Bool
Enables particle interpolation, which makes the particle movement smoother when their
fixedFps
is lower than the screen refresh rate.var lifetime: Double
The amount of time each particle will exist (in seconds). The effective emission rate is
(amount * amount_ratio) / lifetime
particles per second.var localCoords: Bool
If
true
, particles use the parent node’s coordinate space (known as local coordinates). This will cause particles to move and rotate along theGPUParticles2D
node (and its parents) when it is moved or rotated. Iffalse
, particles use global coordinates; they will not move or rotate along theGPUParticles2D
node (and its parents) when it is moved or rotated.var oneShot: Bool
If
true
, only one emission cycle occurs. If settrue
during a cycle, emission will stop at the cycle’s end.var preprocess: Double
Particle system starts as if it had already run for this many seconds.
var processMaterial: Material?
Material
for processing particles. Can be aParticleProcessMaterial
or aShaderMaterial
.var randomness: Double
Emission lifetime randomness ratio.
var speedScale: Double
Particle system’s running speed scaling ratio. A value of
0
can be used to pause the particles.var subEmitter: NodePath
Path to another
GPUParticles2D
node that will be used as a subemitter (seesubEmitterMode
). Subemitters can be used to achieve effects such as fireworks, sparks on collision, bubbles popping into water drops, and more.var texture: Texture2D?
Particle texture. If
null
, particles will be squares with a size of 1×1 pixels.var trailEnabled: Bool
If
true
, enables particle trails using a mesh skinning system.var trailLifetime: Double
The amount of time the particle’s trail should represent (in seconds). Only effective if
trailEnabled
istrue
.var trailSectionSubdivisions: Int32
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
trailSections
. Only effective iftrailEnabled
istrue
.var trailSections: Int32
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
trailSectionSubdivisions
. Only effective iftrailEnabled
istrue
.var visibilityRect: Rect2
The
Rect2
that determines the node’s region which needs to be visible on screen for the particle system to be active.func captureRect(
) -> Rect2 Returns a rectangle containing the positions of all existing particles.
func convertFromParticles(Node?
) Sets this node’s properties to match a given
CPUParticles2D
node.func emitParticle(xform: Transform2D, velocity: Vector2, color: Color, custom: Color, flags: UInt32
) Emits a single particle. Whether
xform
,velocity
,color
andcustom
are applied depends on the value offlags
. SeeEmitFlags
.func restart(
) Restarts the particle emission cycle, clearing existing particles. To avoid particles vanishing from the viewport, wait for the [signal finished] signal before calling.