Animated fire & smoke particles
This commit is contained in:
@@ -42,6 +42,9 @@ namespace Barotrauma.Particles
|
||||
private Hull currentHull;
|
||||
|
||||
private List<Gap> hullGaps;
|
||||
|
||||
private float animState;
|
||||
private int animFrame;
|
||||
|
||||
public ParticlePrefab.DrawTargetType DrawTarget
|
||||
{
|
||||
@@ -77,6 +80,9 @@ namespace Barotrauma.Particles
|
||||
|
||||
spriteIndex = Rand.Int(prefab.Sprites.Count);
|
||||
|
||||
animState = 0;
|
||||
animFrame = 0;
|
||||
|
||||
currentHull = Hull.FindHull(position, hullGuess);
|
||||
|
||||
this.position = position;
|
||||
@@ -166,6 +172,13 @@ namespace Barotrauma.Particles
|
||||
color.R / 255.0f + prefab.ColorChange.X * deltaTime,
|
||||
color.G / 255.0f + prefab.ColorChange.Y * deltaTime,
|
||||
color.B / 255.0f + prefab.ColorChange.Z * deltaTime);
|
||||
|
||||
if (prefab.Sprites[spriteIndex] is SpriteSheet)
|
||||
{
|
||||
animState += deltaTime;
|
||||
int frameCount = ((SpriteSheet)prefab.Sprites[spriteIndex]).FrameCount;
|
||||
animFrame = (int)Math.Min(Math.Floor(animState / prefab.AnimDuration * frameCount), frameCount - 1);
|
||||
}
|
||||
|
||||
if (prefab.DeleteOnCollision || prefab.CollidesWithWalls)
|
||||
{
|
||||
@@ -317,11 +330,25 @@ namespace Barotrauma.Particles
|
||||
drawSize *= ((totalLifeTime - lifeTime) / prefab.GrowTime);
|
||||
}
|
||||
|
||||
prefab.Sprites[spriteIndex].Draw(spriteBatch,
|
||||
new Vector2(drawPosition.X, -drawPosition.Y),
|
||||
color * alpha,
|
||||
prefab.Sprites[spriteIndex].Origin, drawRotation,
|
||||
drawSize, SpriteEffects.None, prefab.Sprites[spriteIndex].Depth);
|
||||
if (prefab.Sprites[spriteIndex] is SpriteSheet)
|
||||
{
|
||||
((SpriteSheet)prefab.Sprites[spriteIndex]).Draw(
|
||||
spriteBatch, animFrame,
|
||||
new Vector2(drawPosition.X, -drawPosition.Y),
|
||||
color * alpha,
|
||||
prefab.Sprites[spriteIndex].Origin, drawRotation,
|
||||
drawSize, SpriteEffects.None, prefab.Sprites[spriteIndex].Depth);
|
||||
}
|
||||
else
|
||||
{
|
||||
prefab.Sprites[spriteIndex].Draw(spriteBatch,
|
||||
new Vector2(drawPosition.X, -drawPosition.Y),
|
||||
color * alpha,
|
||||
prefab.Sprites[spriteIndex].Origin, drawRotation,
|
||||
drawSize, SpriteEffects.None, prefab.Sprites[spriteIndex].Depth);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,9 @@ namespace Barotrauma.Particles
|
||||
|
||||
public readonly List<Sprite> Sprites;
|
||||
|
||||
public readonly float AnimDuration;
|
||||
public readonly bool LoopAnim;
|
||||
|
||||
public readonly float AngularVelocityMin, AngularVelocityMax;
|
||||
|
||||
public readonly float StartRotationMin, StartRotationMax;
|
||||
@@ -53,11 +56,21 @@ namespace Barotrauma.Particles
|
||||
|
||||
foreach (XElement subElement in element.Elements())
|
||||
{
|
||||
if (subElement.Name.ToString().ToLowerInvariant() != "sprite") continue;
|
||||
|
||||
Sprites.Add(new Sprite(subElement));
|
||||
switch (subElement.Name.ToString().ToLowerInvariant())
|
||||
{
|
||||
case "sprite":
|
||||
Sprites.Add(new Sprite(subElement));
|
||||
break;
|
||||
case "spritesheet":
|
||||
case "animatedsprite":
|
||||
Sprites.Add(new SpriteSheet(subElement));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
AnimDuration = ToolBox.GetAttributeFloat(element, "animduration", 1.0f);
|
||||
LoopAnim = ToolBox.GetAttributeBool(element, "loopanim", true);
|
||||
|
||||
if (element.Attribute("angularvelocity") == null)
|
||||
{
|
||||
AngularVelocityMin = ToolBox.GetAttributeFloat(element, "angularvelocitymin", 0.0f);
|
||||
@@ -134,7 +147,9 @@ namespace Barotrauma.Particles
|
||||
DeleteOnCollision = ToolBox.GetAttributeBool(element, "deleteoncollision", false);
|
||||
CollidesWithWalls = ToolBox.GetAttributeBool(element, "collideswithwalls", false);
|
||||
|
||||
CollisionRadius = ToolBox.GetAttributeFloat(element, "collisionradius", Sprites[0].SourceRect.Width/2.0f);
|
||||
CollisionRadius = ToolBox.GetAttributeFloat(element,
|
||||
"collisionradius",
|
||||
Sprites.Count > 0 ? 1 : Sprites[0].SourceRect.Width / 2.0f);
|
||||
|
||||
ColorChange = ToolBox.GetAttributeVector4(element, "colorchange", Vector4.Zero);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user