2D Partikelsysteme¶
Einführung¶
Es wird ein einfaches (aber für die meisten Anwendungen flexibles) Partikelsystem bereitgestellt. Partikelsysteme werden verwendet, um komplexe physikalische Effekte wie Funken, Feuer, magische Partikel, Rauch, Nebel usw. zu simulieren.
Die Idee ist, dass ein "Partikel" in einem festen Intervall und mit einer festen Lebensdauer emittiert wird. Während seiner Lebensdauer hat jedes Partikel das gleiche Grundverhalten. Was jedes Partikel von den anderen unterscheidet und ein organischeres Aussehen bietet, ist die "Zufälligkeit", die jedem Parameter zugeordnet ist. Im Wesentlichen bedeutet das Erstellen eines Partikelsystems, dass physikalische Basisparameter festgelegt und dann Zufälligkeiten hinzugefügt werden.
Partikel-Nodes¶
Godot provides two different nodes for 2D particles, Particles2D and CPUParticles2D. Particles2D is more advanced and uses the GPU to process particle effects, but that limits it to higher end graphics API, and in our case to the GLES3 renderer. For projects using the GLES2 backend, CPUParticles2D is a CPU-driven option with near feature parity with Particles2D, but lesser performance. While Particles2D is configured via a ParticlesMaterial (and optionally with a custom shader), the matching options are provided via node properties in CPUParticles2D (with the exception of the trail settings). You can convert a Particles2D node into a CPUParticles2D node by clicking on the node in the inspector, and selecting "Convert to CPUParticles2D" in the "Particles" menu of the toolbar.

The rest of this tutorial is going to use the Particles2D node. First, add a Particles2D node to your scene. After creating that node you will notice that only a white dot was created, and that there is a warning icon next to your Particles2D node in the inspector. This is because the node needs a ParticlesMaterial to function.
Partikel Materialien¶
To add a process material to your particles node, go to Process Material
in
your inspector panel. Click on the box next to Material
, and from the dropdown
menu select New ParticlesMaterial
.

Ihr Particles2D-Node sollte jetzt weiße Punkte nach unten senden.

Texturen¶
A particle system uses a single texture (in the future this might be extended to animated textures via spritesheet). The texture is set via the relevant texture property:

Zeitparameter¶
Lebensdauer¶
Die Zeit in Sekunden, in der jedes Partikel am Leben bleibt. Wenn die Lebensdauer endet, wird ein neues Partikel erstellt, um es zu ersetzen.
Lebensdauer: 0.5

Lebensdauer: 4.0

Einmalig¶
Wenn diese Option aktiviert ist, gibt ein Particles2D-Node alle seine Partikel einmal und dann nie wieder aus.
Vorverarbeitung¶
Partikelsysteme beginnen mit null emittierten Partikeln und beginnen dann zu emittieren. Dies kann eine Unannehmlichkeit sein, wenn eine Szene geladen wird und Systeme wie Fackel, Nebel usw. in dem Moment, in dem Sie eintreten, zu emittieren beginnen. Mit der Vorverarbeitung kann das System eine bestimmte Anzahl von Sekunden verarbeiten, bevor es beim ersten Mal tatsächlich gezeichnet wird.
Geschwindigkeitsskala¶
The speed scale has a default value of 1
and is used to adjust the
speed of a particle system. Lowering the value will make the particles
slower while increasing the value will make the particles much faster.
Explosivität¶
If lifetime is 1
and there are 10 particles, it means a particle
will be emitted every 0.1 seconds. The explosiveness parameter changes
this, and forces particles to be emitted all together. Ranges are:
- 0: Partikel in regelmäßigen Abständen emittieren (Standardwert).
- 1: Alle Partikel gleichzeitig emittieren.
Werte dazwischen sind ebenfalls zulässig. Diese Funktion ist nützlich, um Explosionen oder plötzliche Partikelausbrüche zu erzeugen:

Zufälligkeit¶
Alle physikalischen Parameter können zufallsbestimmt werden. Zufällige Werte reichen von 0
bis 1
. Die Formel um einen Parameter per Zufall zu bestimmen lautet:
initial_value = param_value + param_value * randomness
feste FPS¶
This setting can be used to set the particle system to render at a fixed
FPS. For instance, changing the value to 2
will make the particles render
at 2 frames per second. Note this does not slow down the particle system itself.
Fract Delta¶
Dies kann verwendet werden, um Fract Delta ein oder auszuschalten.
Zeichnungsparameter¶
sichtbares Recheck¶
The visibility rectangle controls the visibility of the particles on screen. If this rectangle is outside of the viewport, the engine will not render the particles on screen.
The rectangle's W
and H
properties respectively control its Width and its Height.
The X
and Y
properties control the position of the upper-left
corner of the rectangle, relative to the particle emitter.
You can have Godot generate a Visibility Rect automatically using the toolbar above the 2d view. To do so, select the Particles2D node and Click Particles > Generate Visibility Rect
. Godot will simulate the Particles2D node emitting particles for a few seconds and set the rectangle to fit the surface the particles take.
You can control the emit duration with the Generation Time (sec)
option. The maximum value is 25 seconds. If you need more time for your particles to move around, you can temporarily change the preprocess
duration on the Particles2D node.
Lokale Koordinaten¶
Standardmäßig ist diese Option aktiviert. Dies bedeutet, dass der Raum, in den Partikel emittiert werden, relativ zum Node ist. Wenn der Node verschoben wird, werden alle Partikel mit verschoben:

Wenn diese Option deaktiviert ist, werden Partikel in den globalen Raum emittiert. Wenn der Node verschoben wird, sind bereits emittierte Partikel nicht betroffen:

Zeichnungsreihenfolge¶
This controls the order in which individual particles are drawn. Index
means particles are drawn according to their emission order (default).
Lifetime
means they are drawn in order of remaining lifetime.
ParticlesMaterial settings¶
Richtung¶
This is the base direction at which particles emit. The default is
Vector3(1, 0, 0)
which makes particles emit to the right. However,
with the default gravity settings, particles will go straight down.

For this property to be noticeable, you need an initial velocity greater than 0. Here, we set the initial velocity to 40. You'll notice that particles emit toward the right, then go down because of gravity.

Ausbreitung¶
This parameter is the angle in degrees which will be randomly added in
either direction to the base Direction
. A spread of 180
will emit
in all directions (+/- 180). For spread to do anything the "Initial Velocity"
parameter must be greater than 0.

Flatness¶
This property is only useful for 3D particles.
Anfangsgeschwindigkeit¶
Initial velocity is the speed at which particles will be emitted (in pixels/sec). Speed might later be modified by gravity or other accelerations (as described further below).

Winkelgeschwindigkeit¶
Die Winkelgeschwindigkeit ist die anfängliche Winkelgeschwindigkeit, die auf Partikel angewendet wird.
Spin-Geschwindigkeit¶
Die Spin-Geschwindigkeit ist die Geschwindigkeit, mit der sich Partikel um ihr Zentrum drehen (in Grad/Sek.).

Umlaufgeschwindigkeit¶
Die Umlaufgeschwindigkeit wird verwendet, um Partikel dazu zu bringen, sich um ihr Zentrum zu drehen.

Lineare Beschleunigung¶
Die lineare Beschleunigung, die auf jedes Teilchen angewendet wird.
Radiale Beschleunigung¶
Wenn diese Beschleunigung positiv ist, werden Partikel vom Zentrum weg beschleunigt. Wenn sie negativ sind, werden sie dazu angezogen.

Tangentiale Beschleunigung¶
Diese Beschleunigung verwendet den Tangentenvektor zur Mitte. Die Kombination mit Radialbeschleunigung kann schöne Effekte erzielen.

Dämpfung¶
Damping applies friction to the particles, forcing them to stop. It is especially useful for sparks or explosions, which usually begin with a high linear velocity and then stop as they fade.

Winkel¶
Bestimmt den Anfangswinkel des Partikels (in Grad). Dieser Parameter wird meistens zufällig genutzt.

Farbe¶
Wird verwendet, um die Farbe der emittierten Partikel zu ändern.
Farbtonvariation¶
The Variation
value sets the initial hue variation applied to each
particle. The Variation Random
value controls the hue variation
randomness ratio.
Emissionformen¶
ParticlesMaterials allow you to set an Emission Mask, which dictates the area and direction in which particles are emitted. These can be generated from textures in your project.
Ensure that a ParticlesMaterial is set, and the Particles2D node is selected. A "Particles" menu should appear in the Toolbar:

Open it and select "Load Emission Mask":

Then select which texture you want to use as your mask:

Ein Eingabefenster mit diversen Einstellungen wird erscheinen.
Emissionsmaske¶
Three types of emission masks can be generated from a texture:
- Solid Pixels: Particles will spawn from any area of the texture, excluding transparent areas.

- Border Pixels: Particles will spawn from the outer edges of the texture.

- Directed Border Pixels: Similar to Border Pixels, but adds extra
information to the mask to give particles the ability to emit away
from the borders. Note that an
Initial Velocity
will need to be set in order to utilize this.

Emissionsfarben¶
Capture from Pixel
will cause the particles to inherit the color of the mask at their spawn points.
Once you click "OK", the mask will be generated and set to the ParticlesMaterial, under the Emission Shape
section:

All of the values within this section have been automatically generated by the "Load Emission Mask" menu, so they should generally be left alone.
Bemerkung
An image should not be added to Point Texture
or Color Texture
directly.
The "Load Emission Mask" menu should always be used instead.