Skip to content

tutorial_particles_2d

reduz edited this page Nov 4, 2014 · 9 revisions

Particle Systems (2D)

Intro

A simple (but flexible enough for most uses) particle system is provided. Particle systems are used to simulate complex physical effects such as sparks, fire, magic particles, smoke, mist, magic, etc.

The idea is that a "particle" is emitted every a fixed interval and with a fixed lifetime. During his lifetime, every particle will have the same base behavior. What makes every particle different and provides a more organic look is the "randomness" associated to each parameter. In essence, creating a particle system means setting base physics parameters and then adding randomness to them.

Particles2D

Particle systems are added to the scene via the Particles2D node. They are enabled by default and start emitting white points downwards (as affected by the gravity). This provides a reasonable starting point to start adapting it to our needs.

Texture

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:

Physics Variables

Before taking a look at the global parameters for the particle system, let's first see what happens when the physics variables are tweaked.

Direction

This is the base angle at which particles emit. Default is 0 (down):

Changing it will change the emissor direction, but gravity will still affect them:

This parameter is useful because, by rotating the node, gravity will also be rotated. Changing direction keeps them separate.

Spread

Spread is the angle at which particles will randomly be emitted. Increasing the spread will increase the angle. A spread of 180 will emit in all directions.

Linear Velocity

Linear Velocity is the speed at which particles will be emitted (in pixels/sec). Speed might later be modified by gravity or other acceleations (as described further below).

Spin Velocity

Spin Velocity is the speed at which particles turn around their center (in degrees/sec).

Orbit Velocity

Orbit Velocity is used to make particles turn around their center.

Gravity Direction & Strength

Gravity can be modified as in direction and strength. Gravity affects every particle currently alive.

Radial Acceleration

If this acceleration is positive, particles are accelerated away from the center. If negative, they are absorbed towards it.

Tangential Acceleration

This acceleration will use the tangent vector to the center. Combined with Radial Acceleration can do nice effects.

Damping

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

Initial Angle

Determines the intial angle of the particle (in degress). This parameter is mostly useful randomized.

Initial & Final Size

Determines the intial and final scales of the particle.

Color Phases

Particles can use up to 4 color phases. Each color phase can include transparency. Phases must provide an offset value from 0 to 1, and alays in ascending order. For example, a color will begin at offset 0 and end in offset 1, but 4 colors might use diferent offsets, such as 0, 0.2, 0.8 and 1.0 for the different phases:

Will result in:

Clone this wiki locally