Particles
MonoGame.Extended.Particles is ported from the Mercury Particle Engine. A particle engine helps you simulate phenomena, which are otherwise very hard to reproduce with conventional rendering techniques. examples include replicating fire, explosions, smoke, moving water, sparks.
Installation
MonoGame.Extended.Particles is distributed via a NuGet package. You can add the NuGet package to your C# project through your IDE of choice (Visual Studio, Xamarin Studio, Rider, etc) or through the Command Line Interface (CLI) using the dotnet command.
Quick start
We start by including the required namespaces.
Next, we declare our ParticleEffect
and Texture2D
fields
Which we assign in the LoadContent
function
Since _particleTexture
and _particleEffect
are not loaded with the ContentManager
, we need to dispose them in UnloadContent
.
Finaly, we add implement Update
and Draw
Profiles
Profiles determine how the particles are distributed
CircleProfile
The Circle profile distributes the particles within a circle
CircleRadiation
Determines the heading direction of the particles
Code
PointProfile
The Point profile distributes the particles at the same point
Code
BoxProfile
The Box profile distributes the particles over the edge of a box
note
The box profile distributed 25% of the particle on each edge. If you have a rectangular shape and you want an even distribution, use the BoxUniform profile
Code
BoxUniformProfile
The BoxUniform profile evenly distributes the particles over the edge of a box
Code
BoxFillProfile
The BoxFill profile distributes the particles within a box
Code
LineProfile
The Line profile distributes the particles over a line
Code
RingProfile
The Ring profile distributes the particles over a line
CircleRadiation
Determines the heading direction of the particles
Code
SprayProfile
The Spray profile prays the particles in a given direction
Code
Modifiers
AgeModifier
The AgeModifier
Uses Interpolators to modify the particle over its lifespan.
Code
Result
CircleContainerModifier
This Modifier makes the particles collide with a circle container.
Radius
The radius of the CircleContainer
.
Inside
Whether the particles should stay inside the of outside the container
RestitutionCoefficient
The bounces back force of the particles
Code
Result
RectangleContainerModifier
This Modifier makes the particles collide with a rectangle container.
Width
Width of the container
Height
Height of the container
RestitutionCoefficient
The bounces back force of the particles
Code
Result
RectangleLoopContainerModifier
This Modifier keeps the particles inside a rectangular container by looping them around.
Width
Width of the container
Height
Height of the container
Code
Result
DragModifier
The DragModifier
simulates the effects of the particle passing through a medium such as water, air, etc., which exert a force (drag) which slows the particles down.
DragCoefficient
The drag coefficient of the particle.
Density
The density of the medium through which the particle is moving.
Code
Result
LinearGravityModifier
LinearGravityModifier
applies linear gravity to the particle
Direction
The direction of gravity.
Strength
Strength of the gravity
Code
Result
OpacityFastFadeModifier
OpacityFastFadeModifier
fades the particles over the span of their lifetime
Code
Result
RotationModifier
The RotationModifier
rotates the particles by a given RotationRate
Code
Result
VelocityColorModifier
The VelocityColorModifier
Colors the particle by its velocity
StationaryColor
The color when the velocity is 0
VelocityColor
The particle color when it reaches the VelocityThreshold
VelocityThreshold
The threshold of the velocity
Code
Result
VelocityModifier
The VelocityModifier
Uses Interpolators
to modify the particles depending on their velocity.
Code
Result
VortexModifier
This VortexModifier
moves the particles in a whirling vortex. This can be used for creating wind effects, etc.
Mass
The mass of the vortex
Position
The position of the vortex relative to the ParticleEmitter
Code
Result
Interpolators
Interpolators are used by AgeModifier
and VelocityModifier
to interpolate particle properties
ColorInterpolator
The ColorInterpolator
Interpolates from a Start to an End color.
Code
Result
HueInterpolator
The HueInterpolator
Interpolates from a Start to an End Hue.
note
Make sure to set the particle color
Code
Result
OpacityInterpolator
The OpacityInterpolator
Interpolates from a Start to an End Opacity.
Code
Result
RotationInterpolator
The RotationInterpolator
Interpolates from a Start to an End Rotation.
Code
Result
ScaleInterpolator
The ScaleInterpolator
Interpolates from a Start to an End Scale.
Code
Result