Documentation
¶
Overview ¶
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.
Index ¶
- type Advanced
- type Any
- type DrawOrder
- type EmitFlags
- type Expanded
- type Extension
- type ID
- type Instance
- func (self Instance) Amount() int
- func (self Instance) AmountRatio() Float.X
- func (self Instance) AsCanvasItem() CanvasItem.Instance
- func (self Instance) AsGPUParticles2D() Instance
- func (self Instance) AsNode() Node.Instance
- func (self Instance) AsNode2D() Node2D.Instance
- func (self Instance) AsObject() [1]gd.Object
- func (self Instance) CaptureRect() Rect2.PositionSize
- func (self Instance) CollisionBaseSize() Float.X
- func (self Instance) ConvertFromParticles(particles Node.Instance)
- func (self Instance) DrawOrder() DrawOrder
- func (self Instance) EmitParticle(xform Transform2D.OriginXY, velocity Vector2.XY, color Color.RGBA, ...)
- func (self Instance) Emitting() bool
- func (self Instance) Explosiveness() Float.X
- func (self Instance) FixedFps() int
- func (self Instance) FractDelta() bool
- func (self Instance) ID() ID
- func (self Instance) InterpToEnd() Float.X
- func (self Instance) Interpolate() bool
- func (self Instance) Lifetime() Float.X
- func (self Instance) LocalCoords() bool
- func (self Instance) MoreArgs() MoreArgs
- func (self Instance) OnFinished(cb func(), flags ...Signal.Flags)
- func (self Instance) OneShot() bool
- func (self Instance) Preprocess() Float.X
- func (self Instance) ProcessMaterial() Material.Instance
- func (self Instance) Randomness() Float.X
- func (self Instance) RequestParticlesProcess(process_time Float.X)
- func (self Instance) Restart()
- func (self Instance) Seed() int
- func (self Instance) SetAmount(value int)
- func (self Instance) SetAmountRatio(value Float.X)
- func (self Instance) SetCollisionBaseSize(value Float.X)
- func (self Instance) SetDrawOrder(value DrawOrder)
- func (self Instance) SetEmitting(value bool)
- func (self Instance) SetExplosiveness(value Float.X)
- func (self Instance) SetFixedFps(value int)
- func (self Instance) SetFractDelta(value bool)
- func (self Instance) SetInterpToEnd(value Float.X)
- func (self Instance) SetInterpolate(value bool)
- func (self Instance) SetLifetime(value Float.X)
- func (self Instance) SetLocalCoords(value bool)
- func (self *Instance) SetObject(obj [1]gd.Object) bool
- func (self Instance) SetOneShot(value bool)
- func (self Instance) SetPreprocess(value Float.X)
- func (self Instance) SetProcessMaterial(value Material.Instance)
- func (self Instance) SetRandomness(value Float.X)
- func (self Instance) SetSeed(value int)
- func (self Instance) SetSpeedScale(value Float.X)
- func (self Instance) SetSubEmitter(value string)
- func (self Instance) SetTexture(value Texture2D.Instance)
- func (self Instance) SetTrailEnabled(value bool)
- func (self Instance) SetTrailLifetime(value Float.X)
- func (self Instance) SetTrailSectionSubdivisions(value int)
- func (self Instance) SetTrailSections(value int)
- func (self Instance) SetUseFixedSeed(value bool)
- func (self Instance) SetVisibilityRect(value Rect2.PositionSize)
- func (self Instance) SpeedScale() Float.X
- func (self Instance) SubEmitter() string
- func (self Instance) Texture() Texture2D.Instance
- func (self Instance) TrailEnabled() bool
- func (self Instance) TrailLifetime() Float.X
- func (self Instance) TrailSectionSubdivisions() int
- func (self Instance) TrailSections() int
- func (self Instance) UseFixedSeed() bool
- func (self Instance) Virtual(name string) reflect.Value
- func (self Instance) VisibilityRect() Rect2.PositionSize
- type MoreArgs
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Advanced ¶
type Advanced = class
Advanced exposes a 1:1 low-level instance of the class, undocumented, for those who know what they are doing.
type DrawOrder ¶
type DrawOrder int //gd:GPUParticles2D.DrawOrder
const ( // Particles are drawn in the order emitted. DrawOrderIndex DrawOrder = 0 // Particles are drawn in order of remaining lifetime. In other words, the particle with the highest lifetime is drawn at the front. DrawOrderLifetime DrawOrder = 1 // Particles are drawn in reverse order of remaining lifetime. In other words, the particle with the lowest lifetime is drawn at the front. DrawOrderReverseLifetime DrawOrder = 2 )
type EmitFlags ¶
type EmitFlags int //gd:GPUParticles2D.EmitFlags
const ( // Particle starts at the specified position. EmitFlagPosition EmitFlags = 1 // Particle starts with specified rotation and scale. EmitFlagRotationScale EmitFlags = 2 // Particle starts with the specified velocity vector, which defines the emission direction and speed. EmitFlagVelocity EmitFlags = 4 // Particle starts with specified color. EmitFlagColor EmitFlags = 8 // Particle starts with specified CUSTOM data. EmitFlagCustom EmitFlags = 16 )
type Extension ¶
Extension can be embedded in a new struct to create an extension of this class. T should be the type that is embedding this Extension
func (*Extension[T]) AsCanvasItem ¶
func (self *Extension[T]) AsCanvasItem() CanvasItem.Instance
func (*Extension[T]) AsGPUParticles2D ¶
type ID ¶
ID is a typed object ID (reference) to an instance of this class, use it to store references to objects with unknown lifetimes, as an ID will not panic on use if the underlying object has been destroyed.
type Instance ¶
type Instance [1]gdclass.GPUParticles2D
Instance of the class with convieniently typed arguments and results.
var Nil Instance
Nil is a nil/null instance of the class. Equivalent to the zero value.
func (Instance) Amount ¶
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 AmountRatio is decreased.
Note: Changing this value will cause the particle system to restart. To avoid this, change AmountRatio instead.
func (Instance) AmountRatio ¶
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 Amount, changing AmountRatio 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.
Note: Reducing the AmountRatio has no performance benefit, since resources need to be allocated and processed for the total Amount of particles regardless of the AmountRatio. If you don't intend to change the number of particles emitted while the particles are emitting, make sure AmountRatio is set to 1 and change Amount to your liking instead.
func (Instance) AsCanvasItem ¶
func (self Instance) AsCanvasItem() CanvasItem.Instance
func (Instance) AsGPUParticles2D ¶
func (Instance) CaptureRect ¶
func (self Instance) CaptureRect() Rect2.PositionSize
Returns a rectangle containing the positions of all existing particles.
Note: When using threaded rendering this method synchronizes the rendering thread. Calling it often may have a negative impact on performance.
func (Instance) CollisionBaseSize ¶
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.CollisionRigid] or [Particleprocessmaterial.CollisionHideOnContact].
Note: Particles always have a spherical collision shape.
func (Instance) ConvertFromParticles ¶
Sets this node's properties to match a given CPUParticles2D node.
func (Instance) EmitParticle ¶
func (self Instance) EmitParticle(xform Transform2D.OriginXY, velocity Vector2.XY, color Color.RGBA, custom Color.RGBA, flags int)
Emits a single particle. Whether 'xform', 'velocity', 'color' and 'custom' are applied depends on the value of 'flags'. See EmitFlags.
The default ParticleProcessMaterial will overwrite 'color' and use the contents of 'custom' as (rotation, age, animation, lifetime).
Note: EmitParticle is only supported on the Forward+ and Mobile rendering methods, not Compatibility.
func (Instance) Emitting ¶
If true, particles are being emitted. Emitting can be used to start and stop particles from emitting. However, if OneShot is true setting Emitting to true will not restart the emission cycle unless all active particles have finished processing. Use the OnFinished signal to be notified once all active particles finish processing.
Note: For OneShot emitters, due to the particles being computed on the GPU, there may be a short period after receiving the OnFinished signal during which setting this to true will not restart the emission cycle.
Tip: If your OneShot emitter needs to immediately restart emitting particles once OnFinished signal is received, consider calling Restart instead of setting Emitting.
func (Instance) Explosiveness ¶
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.
func (Instance) FixedFps ¶
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.
func (Instance) FractDelta ¶
If true, results in fractional delta calculation which has a smoother particles display effect.
func (Instance) InterpToEnd ¶
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.
func (Instance) Interpolate ¶
Enables particle interpolation, which makes the particle movement smoother when their FixedFps is lower than the screen refresh rate.
func (Instance) Lifetime ¶
The amount of time each particle will exist (in seconds). The effective emission rate is (amount * amount_ratio) / lifetime particles per second.
func (Instance) LocalCoords ¶
If true, particles use the parent node's coordinate space (known as local coordinates). This will cause particles to move and rotate along the GPUParticles2D node (and its parents) when it is moved or rotated. If false, particles use global coordinates; they will not move or rotate along the GPUParticles2D node (and its parents) when it is moved or rotated.
func (Instance) MoreArgs ¶
MoreArgs enables certain functions to be called with additional 'optional' arguments.
func (Instance) OnFinished ¶
Emitted when all active particles have finished processing. To immediately restart the emission cycle, call Restart.
This signal is never emitted when OneShot is disabled, as particles will be emitted and processed continuously.
Note: For OneShot emitters, due to the particles being computed on the GPU, there may be a short period after receiving the signal during which setting Emitting to true will not restart the emission cycle. This delay is avoided by instead calling Restart.
func (Instance) OneShot ¶
If true, only one emission cycle occurs. If set true during a cycle, emission will stop at the cycle's end.
func (Instance) Preprocess ¶
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 FixedFps (or 30, if 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.
func (Instance) ProcessMaterial ¶
Material for processing particles. Can be a ParticleProcessMaterial or a ShaderMaterial.
func (Instance) Randomness ¶
Emission lifetime randomness ratio.
func (Instance) RequestParticlesProcess ¶
Requests the particles to process for extra process time during a single frame.
Useful for particle playback, if used in combination with UseFixedSeed or by calling Restart with parameter keep_seed set to true.
func (Instance) Restart ¶
func (self Instance) Restart()
Restarts the particle emission cycle, clearing existing particles. To avoid particles vanishing from the viewport, wait for the OnFinished signal before calling.
Note: The OnFinished signal is only emitted by OneShot emitters.
If 'keep_seed' is true, the current random seed will be preserved. Useful for seeking and playback.
func (Instance) Seed ¶
Sets the random seed used by the particle system. Only effective if UseFixedSeed is true.
func (Instance) SetAmountRatio ¶
SetAmountRatio sets the property returned by [GetAmountRatio].
func (Instance) SetCollisionBaseSize ¶
SetCollisionBaseSize sets the property returned by [GetCollisionBaseSize].
func (Instance) SetDrawOrder ¶
SetDrawOrder sets the property returned by [GetDrawOrder].
func (Instance) SetEmitting ¶
SetEmitting sets the property returned by [IsEmitting].
func (Instance) SetExplosiveness ¶
SetExplosiveness sets the property returned by [GetExplosivenessRatio].
func (Instance) SetFixedFps ¶
SetFixedFps sets the property returned by [GetFixedFps].
func (Instance) SetFractDelta ¶
SetFractDelta sets the property returned by [GetFractionalDelta].
func (Instance) SetInterpToEnd ¶
SetInterpToEnd sets the property returned by [GetInterpToEnd].
func (Instance) SetInterpolate ¶
SetInterpolate sets the property returned by [GetInterpolate].
func (Instance) SetLifetime ¶
SetLifetime sets the property returned by [GetLifetime].
func (Instance) SetLocalCoords ¶
SetLocalCoords sets the property returned by [GetUseLocalCoordinates].
func (Instance) SetOneShot ¶
SetOneShot sets the property returned by [GetOneShot].
func (Instance) SetPreprocess ¶
SetPreprocess sets the property returned by [GetPreProcessTime].
func (Instance) SetProcessMaterial ¶
SetProcessMaterial sets the property returned by [GetProcessMaterial].
func (Instance) SetRandomness ¶
SetRandomness sets the property returned by [GetRandomnessRatio].
func (Instance) SetSpeedScale ¶
SetSpeedScale sets the property returned by [GetSpeedScale].
func (Instance) SetSubEmitter ¶
SetSubEmitter sets the property returned by [GetSubEmitter].
func (Instance) SetTexture ¶
SetTexture sets the property returned by [GetTexture].
func (Instance) SetTrailEnabled ¶
SetTrailEnabled sets the property returned by [IsTrailEnabled].
func (Instance) SetTrailLifetime ¶
SetTrailLifetime sets the property returned by [GetTrailLifetime].
func (Instance) SetTrailSectionSubdivisions ¶
SetTrailSectionSubdivisions sets the property returned by [GetTrailSectionSubdivisions].
func (Instance) SetTrailSections ¶
SetTrailSections sets the property returned by [GetTrailSections].
func (Instance) SetUseFixedSeed ¶
SetUseFixedSeed sets the property returned by [GetUseFixedSeed].
func (Instance) SetVisibilityRect ¶
func (self Instance) SetVisibilityRect(value Rect2.PositionSize)
SetVisibilityRect sets the property returned by [GetVisibilityRect].
func (Instance) SpeedScale ¶
Particle system's running speed scaling ratio. A value of 0 can be used to pause the particles.
func (Instance) SubEmitter ¶
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 SubEmitter is set, the target GPUParticles2D node will no longer emit particles on its own.
func (Instance) Texture ¶
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.
func (Instance) TrailEnabled ¶
If true, enables particle trails using a mesh skinning system.
Note: Unlike GPUParticles3D, the number of trail sections and subdivisions is set with the TrailSections and TrailSectionSubdivisions properties.
func (Instance) TrailLifetime ¶
The amount of time the particle's trail should represent (in seconds). Only effective if TrailEnabled is true.
func (Instance) TrailSectionSubdivisions ¶
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 if TrailEnabled is true.
func (Instance) TrailSections ¶
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 if TrailEnabled is true.
func (Instance) UseFixedSeed ¶
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.
func (Instance) VisibilityRect ¶
func (self Instance) VisibilityRect() Rect2.PositionSize
The Rect2.PositionSize that determines the node's region which needs to be visible on screen for the particle system to be active.
Grow the rect if particles suddenly appear/disappear when the node enters/exits the screen. The Rect2.PositionSize can be grown via code or with the Particles → Generate Visibility Rect editor tool.
type MoreArgs ¶
type MoreArgs [1]gdclass.GPUParticles2D
MoreArgs is a container for Instance functions with additional 'optional' arguments.
func (MoreArgs) Restart ¶
Restarts the particle emission cycle, clearing existing particles. To avoid particles vanishing from the viewport, wait for the OnFinished signal before calling.
Note: The OnFinished signal is only emitted by OneShot emitters.
If 'keep_seed' is true, the current random seed will be preserved. Useful for seeking and playback.