Class Particle
A particle is a MLEM.Animations.SpriteAnimation that can be moved and displayed in world space. A particle is simply a MapObject that does not collide or interact directly with the world, but has all of the same properties. A new particle can be added for display using Spawn(Map, Vector2, Func<Vector2, Particle>).
public class Particle
- Inheritance
-
Particle
- Inherited Members
- Extension Methods
Constructors
Particle(SpriteAnimation, TimeSpan, Vector2, float)
Creates a new particle with the given settings
public Particle(SpriteAnimation animation, TimeSpan timeToLive, Vector2 position, float floor)
Parameters
animation
SpriteAnimationThe animation that this particle should display with
timeToLive
TimeSpanThe amount of real time that this particle should stay alive for
position
Vector2The position that this particle should have, in world space
floor
floatThe floor that this particle is on.
Particle(TextureRegion, TimeSpan, Vector2, float)
Creates a new particle with the given settings
public Particle(TextureRegion region, TimeSpan timeToLive, Vector2 position, float floor)
Parameters
region
TextureRegionThe texture that this particle should display with
timeToLive
TimeSpanThe amount of real time that this particle should stay alive for
position
Vector2The position that this particle should have, in world space
floor
floatThe floor that this particle is on.
Fields
Alpha
The alpha that this particle should draw with.
public float Alpha
Field Value
AmbientFallingLeaves
A set of conditions for FurnitureType instances that should optionally display the falling leaves particles that default trees do. The minimum and maximum spawn heights and horizontal coordinates are in relation to the furniture's position in the world, with all offsets being multiplied by TileWidth or TileHeight. To add additional furniture that displays falling leaves, simply add to this collection.
public static readonly Dictionary<FurnitureType, (float MinSpawnHeight, float MaxSpawnHeight, float MinSpawnX, float MaxSpawnX, float Chance)> AmbientFallingLeaves
Field Value
- Dictionary<FurnitureType, (float MinSpawnHeight, float MaxSpawnHeight, float MinSpawnX, float MaxSpawnX, float Chance)>
Animation
The MLEM.Animations.SpriteAnimation that this particle displays over its lifespan
protected readonly SpriteAnimation Animation
Field Value
- SpriteAnimation
Color
The color to render this particle with, or Microsoft.Xna.Framework.Color.White by default.
public Color Color
Field Value
- Color
DeathAnimation
An action that can be used to animate any part of the particle over the last part of its lifespan. The passed float is the percentage of the given TimeSpan that has passed, where the end of the timespan marks the despawning of the particle.
public (TimeSpan, Action<Particle, float>) DeathAnimation
Field Value
DepthOffset
A value that is passed to GetDepth(Vector2, float, float, bool, bool, bool) as the depth offset when the particle's depth is calculated.
public float DepthOffset
Field Value
DepthPosOffset
An offset that is applied to this particle's Position, in world space, for depth calculations.
public Vector2 DepthPosOffset
Field Value
- Vector2
Floor
The floor that this particle is on.
public float Floor
Field Value
ForceOutside
Whether this particle should always be displayed as if it were outside (rather than in the room its Position is in). This field is used for particles like chimney smoke, which always draw above the room on the outside.
public bool ForceOutside
Field Value
Friction
The friction that is applied to this particle's Motion every Update(GameTime, TimeSpan, float) frame
public Vector2 Friction
Field Value
- Vector2
Gravity
The particle's gravity, which determines how much its VisualMotion is affected every Update(GameTime, TimeSpan, float) frame. Defaults to 0.
public float Gravity
Field Value
IgnoreParentDrawPos
This value indicates whether the visual position of the ParentInfo should be ignored when drawing.
public bool IgnoreParentDrawPos
Field Value
LifeAnimation
An action that can be used to animate any part of the particle over its lifespan. The passed float is the percentage of the particle's lifespan that has passed.
public Action<Particle, float> LifeAnimation
Field Value
Light
The light that this particle should display, which is automatically added and removed from the Map. The light's Scale and Position will be set automatically based on this particle.
public Light Light
Field Value
Motion
The amount that this particle's Position is modified by each Update(GameTime, TimeSpan, float) frame
public Vector2 Motion
Field Value
- Vector2
OnUpdate
An event that is raised when this particle is updated in Update(GameTime, TimeSpan, float). Note that OnParticleUpdate is invoked for all particles, whereas this event is just invoked for this particle.
public ObjectUpdateDelegateNoPhase<Particle> OnUpdate
Field Value
ParentInfo
A ParentInfo that contains the object that this particle should be rendered in relation to.
public ParentInfo ParentInfo
Field Value
Position
The position in the world of this particle
public Vector2 Position
Field Value
- Vector2
Random
The random instance that is used for all particle-related random operations.
protected static readonly Random Random
Field Value
Scale
The scale that this particle should display with.
public float Scale
Field Value
ScreenPosOffset
An offset from this particle's screen-space draw position, also in screen space. This is added to the final draw position in Draw(GameTime, SpriteBatch), after ToScreenPos(Vector2, float, bool, bool, bool) has already been called.
public Vector2 ScreenPosOffset
Field Value
- Vector2
SpawnAnimation
An action that can be used to animate any part of the particle over the first part of its lifespan. The passed float is the percentage of the given TimeSpan that has passed.
public (TimeSpan, Action<Particle, float>) SpawnAnimation
Field Value
SpriteEffects
The SpriteEffects that should be applied when drawing this particle.
public SpriteEffects SpriteEffects
Field Value
- SpriteEffects
TimeLived
The amount of real time that this particle has lived for. This time span will always be lower than or equal to TimeToLive.
protected TimeSpan TimeLived
Field Value
TimeToLive
The amount of real time that this particle should stay alive for until it disappears
public TimeSpan TimeToLive
Field Value
UpdateWhenPaused
This value indicates whether this particle's Update(GameTime, TimeSpan, float) method should still be called when the game is paused. This should be set to true when spawning particles in build mode, as the game is paused during that time.
public bool UpdateWhenPaused
Field Value
VisualMotion
The motion that this particle's VisualWorldOffset is moved by every update frame. If Gravity is set, this value is modified every update frame as well. This value is not affected by Friction.
public Vector2 VisualMotion
Field Value
- Vector2
VisualWorldOffset
An offset from this particle's world-space draw position, also in world space. This is translated to screen space using ToScreenPos(Vector2, float, bool, bool, bool) and added to the final draw position in Draw(GameTime, SpriteBatch).
public Vector2 VisualWorldOffset
Field Value
- Vector2
Properties
Map
The map that the game is currently on. This always returns CurrentMap.
protected static Map Map { get; }
Property Value
Methods
Draw(GameTime, SpriteBatch)
public virtual void Draw(GameTime time, SpriteBatch batch)
Parameters
time
GameTimeThe current time
batch
SpriteBatchThe sprite batch to use for drawing
OnAdded()
This method is called when a particle is successfully spawned in Spawn(Map, Vector2, Func<Vector2, Particle>).
protected virtual void OnAdded()
OnRemoved()
This method is called when a particle is removed in Remove(), or when the camera rotation or viewed map changes.
protected virtual void OnRemoved()
Remove()
Removes this particle from the list of particles and calls its OnRemoved() method.
public void Remove()
Spawn(Map, Vector2, Func<Vector2, Particle>)
Spawns a new particle with the given settings. The particle is only spawned if the resulting display position would currently be visible for the Camera.
public static void Spawn(Map map, Vector2 position, Func<Vector2, Particle> particleFunction)
Parameters
map
MapThe map to spawn on.
position
Vector2The position in world space that the particle should be spawned at.
particleFunction
Func<Vector2, Particle>A function that is invoked if the particle can be spawned.
Update(GameTime, TimeSpan, float)
The update method, which is called every update frame by the underlying Map
public virtual void Update(GameTime time, TimeSpan passedInGame, float speedMultiplier)
Parameters
time
GameTimeThe game's time
passedInGame
TimeSpanThe amount of time that has passed since the last call
speedMultiplier
floatThe game speed multiplier, which represents how fast things should happen, which is usually determined by Speed
Events
OnParticleUpdate
An event that is raised when a Particle is updated in Update(GameTime, TimeSpan, float).
public static event ObjectUpdateDelegate<Particle> OnParticleUpdate