diff --git a/source/MonoGame.Extended/Particles/Data/Particle.cs b/source/MonoGame.Extended/Particles/Data/Particle.cs index 9f650c05..d705cfb7 100644 --- a/source/MonoGame.Extended/Particles/Data/Particle.cs +++ b/source/MonoGame.Extended/Particles/Data/Particle.cs @@ -44,7 +44,7 @@ public unsafe struct Particle /// /// The scale factor applied to this particle's visual representation. /// - public float Scale; + public fixed float Scale[2]; /// /// The position where this particle was triggered or emitted from [X, Y]. diff --git a/source/MonoGame.Extended/Particles/Data/ParticleReleaseParameters.cs b/source/MonoGame.Extended/Particles/Data/ParticleReleaseParameters.cs index 0917bd80..a3dcb6c1 100644 --- a/source/MonoGame.Extended/Particles/Data/ParticleReleaseParameters.cs +++ b/source/MonoGame.Extended/Particles/Data/ParticleReleaseParameters.cs @@ -54,7 +54,7 @@ public class ParticleReleaseParameters /// /// Defaults to a random value between 0.0 (half scale) and 1.0 (full scale) /// - public ParticleFloatParameter Scale = new ParticleFloatParameter(0.5f, 1.0f); + public ParticleVector2Parameter Scale = new ParticleVector2Parameter(new Vector2(0.5f, 0.5f), new Vector2(1.0f, 1.0f)); /// /// Gets or sets the initial rotation (in radians) of particles when released. diff --git a/source/MonoGame.Extended/Particles/Modifiers/Interpolators/ScaleInterpolator.cs b/source/MonoGame.Extended/Particles/Modifiers/Interpolators/ScaleInterpolator.cs index dd198917..fc6606fa 100644 --- a/source/MonoGame.Extended/Particles/Modifiers/Interpolators/ScaleInterpolator.cs +++ b/source/MonoGame.Extended/Particles/Modifiers/Interpolators/ScaleInterpolator.cs @@ -2,6 +2,7 @@ // Licensed under the MIT license. // See LICENSE file in the project root for full license information. +using Microsoft.Xna.Framework; using MonoGame.Extended.Particles.Data; namespace MonoGame.Extended.Particles.Modifiers.Interpolators; @@ -14,7 +15,7 @@ namespace MonoGame.Extended.Particles.Modifiers.Interpolators; /// to based on the /// provided interpolation amount (typically representing the particle's normalized age). /// -public class ScaleInterpolator : Interpolator +public class ScaleInterpolator : Interpolator { /// /// Updates a particle's scale by interpolating between the start and end values. @@ -23,6 +24,7 @@ public class ScaleInterpolator : Interpolator /// A pointer to the particle to update. public override unsafe void Update(float amount, Particle* particle) { - particle->Scale = StartValue + (EndValue - StartValue) * amount; + particle->Scale[0] = StartValue.X + (EndValue.X - StartValue.X) * amount; + particle->Scale[1] = StartValue.Y + (EndValue.Y - StartValue.Y) * amount; } } diff --git a/source/MonoGame.Extended/Particles/ParticleEffectReader.cs b/source/MonoGame.Extended/Particles/ParticleEffectReader.cs index 23fd848f..6a6716c3 100644 --- a/source/MonoGame.Extended/Particles/ParticleEffectReader.cs +++ b/source/MonoGame.Extended/Particles/ParticleEffectReader.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Net; using System.Xml; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Content; @@ -270,7 +271,7 @@ public sealed class ParticleEffectReader : IDisposable break; case nameof(ParticleReleaseParameters.Scale): - parameters.Scale = ReadParticleFloatParameter(subtree); + parameters.Scale = ReadParticleVector2Parameter(subtree); break; case nameof(ParticleReleaseParameters.Rotation): @@ -325,6 +326,25 @@ public sealed class ParticleEffectReader : IDisposable return new ParticleFloatParameter(0); } + private ParticleVector2Parameter ReadParticleVector2Parameter(XmlReader reader) + { + ParticleValueKind kind = reader.GetAttributeEnum(nameof(ParticleVector2Parameter.Kind)); + + if(kind == ParticleValueKind.Constant) + { + Vector2 value = reader.GetAttributeVector2(nameof(ParticleVector2Parameter.Constant)); + return new ParticleVector2Parameter(value); + } + else if(kind == ParticleValueKind.Random) + { + Vector2 min = reader.GetAttributeVector2(nameof(ParticleVector2Parameter.RandomMin)); + Vector2 max = reader.GetAttributeVector2(nameof(ParticleVector2Parameter.RandomMax)); + return new ParticleVector2Parameter(min, max); + } + + return new ParticleVector2Parameter(Vector2.Zero); + } + private ParticleColorParameter ReadParticleColorParameter(XmlReader reader) { ParticleValueKind kind = reader.GetAttributeEnum(nameof(ParticleColorParameter.Kind)); @@ -604,8 +624,8 @@ public sealed class ParticleEffectReader : IDisposable case nameof(ScaleInterpolator): ScaleInterpolator scaleInterpolator = new ScaleInterpolator(); - scaleInterpolator.StartValue = reader.GetAttributeFloat(nameof(ScaleInterpolator.StartValue)); - scaleInterpolator.EndValue = reader.GetAttributeFloat(nameof(ScaleInterpolator.EndValue)); + scaleInterpolator.StartValue = reader.GetAttributeVector2(nameof(ScaleInterpolator.StartValue)); + scaleInterpolator.EndValue = reader.GetAttributeVector2(nameof(ScaleInterpolator.EndValue)); return scaleInterpolator; case nameof(VelocityInterpolator): diff --git a/source/MonoGame.Extended/Particles/ParticleEffectWriter.cs b/source/MonoGame.Extended/Particles/ParticleEffectWriter.cs index 1013cd0b..e02174a5 100644 --- a/source/MonoGame.Extended/Particles/ParticleEffectWriter.cs +++ b/source/MonoGame.Extended/Particles/ParticleEffectWriter.cs @@ -149,7 +149,7 @@ public class ParticleEffectWriter : IDisposable WriteParticleFloatParameter(nameof(ParticleReleaseParameters.Speed), parameters.Speed); WriteParticleColorParameter(nameof(ParticleReleaseParameters.Color), parameters.Color); WriteParticleFloatParameter(nameof(ParticleReleaseParameters.Opacity), parameters.Opacity); - WriteParticleFloatParameter(nameof(ParticleReleaseParameters.Scale), parameters.Scale); + WriteParticleVector2Parameter(nameof(ParticleReleaseParameters.Scale), parameters.Scale); WriteParticleFloatParameter(nameof(ParticleReleaseParameters.Rotation), parameters.Rotation); WriteParticleFloatParameter(nameof(ParticleReleaseParameters.Mass), parameters.Mass); @@ -191,6 +191,24 @@ public class ParticleEffectWriter : IDisposable _writer.WriteEndElement(); } + private void WriteParticleVector2Parameter(string name, ParticleVector2Parameter parameter) + { + _writer.WriteStartElement(name); + _writer.WriteAttributeString(nameof(ParticleVector2Parameter.Kind), parameter.Kind.ToString()); + + if(parameter.Kind == ParticleValueKind.Constant) + { + _writer.WriteAttributeVector2(nameof(ParticleVector2Parameter.Constant), parameter.Constant); + } + else + { + _writer.WriteAttributeVector2(nameof(ParticleVector2Parameter.RandomMin), parameter.RandomMin); + _writer.WriteAttributeVector2(nameof(ParticleVector2Parameter.RandomMax), parameter.RandomMax); + } + + _writer.WriteEndElement(); + } + private void WriteParticleColorParameter(string name, ParticleColorParameter parameter) { _writer.WriteStartElement(name); @@ -403,8 +421,8 @@ public class ParticleEffectWriter : IDisposable case ScaleInterpolator scaleInterpolator: _writer.WriteAttributeString(nameof(Type), nameof(ScaleInterpolator)); - _writer.WriteAttributeFloat(nameof(ScaleInterpolator.StartValue), scaleInterpolator.StartValue); - _writer.WriteAttributeFloat(nameof(ScaleInterpolator.EndValue), scaleInterpolator.EndValue); + _writer.WriteAttributeVector2(nameof(ScaleInterpolator.StartValue), scaleInterpolator.StartValue); + _writer.WriteAttributeVector2(nameof(ScaleInterpolator.EndValue), scaleInterpolator.EndValue); break; case VelocityInterpolator velocityInterpolator: diff --git a/source/MonoGame.Extended/Particles/ParticleEmitter.cs b/source/MonoGame.Extended/Particles/ParticleEmitter.cs index a9f200fc..6513e603 100644 --- a/source/MonoGame.Extended/Particles/ParticleEmitter.cs +++ b/source/MonoGame.Extended/Particles/ParticleEmitter.cs @@ -369,7 +369,11 @@ public sealed unsafe class ParticleEmitter : IDisposable particle->Color[2] = color.Z; particle->Opacity = Parameters.Opacity.Value; - particle->Scale = Parameters.Scale.Value; + + Vector2 scale = Parameters.Scale.Value; + particle->Scale[0] = scale.X; + particle->Scale[1] = scale.Y; + particle->Rotation = Parameters.Rotation.Value; particle->Mass = Parameters.Mass.Value; particle->LayerDepth = layerDepth; diff --git a/source/MonoGame.Extended/Particles/SpriteBatchExtensions.ParticleEfffect.cs b/source/MonoGame.Extended/Particles/SpriteBatchExtensions.ParticleEfffect.cs index eaf21ac7..86e28100 100644 --- a/source/MonoGame.Extended/Particles/SpriteBatchExtensions.ParticleEfffect.cs +++ b/source/MonoGame.Extended/Particles/SpriteBatchExtensions.ParticleEfffect.cs @@ -96,7 +96,7 @@ public static class SpriteBatchExtensions } Vector2 position = new Vector2(particle->Position[0], particle->Position[1]); - float scale = particle->Scale; + Vector2 scale = new Vector2(particle->Scale[0], particle->Scale[1]); float rotation = particle->Rotation; float layerDepth = particle->LayerDepth; diff --git a/tests/MonoGame.Extended.Tests/Particles/ParticleEffectReaderTests.cs b/tests/MonoGame.Extended.Tests/Particles/ParticleEffectReaderTests.cs index 66090066..5fd3a6cc 100644 --- a/tests/MonoGame.Extended.Tests/Particles/ParticleEffectReaderTests.cs +++ b/tests/MonoGame.Extended.Tests/Particles/ParticleEffectReaderTests.cs @@ -87,7 +87,7 @@ public class ParticleEffectReaderTests - + @@ -119,7 +119,7 @@ public class ParticleEffectReaderTests - + @@ -155,7 +155,7 @@ public class ParticleEffectReaderTests - + @@ -189,7 +189,7 @@ public class ParticleEffectReaderTests - + @@ -223,7 +223,7 @@ public class ParticleEffectReaderTests - + @@ -257,7 +257,7 @@ public class ParticleEffectReaderTests - + @@ -291,7 +291,7 @@ public class ParticleEffectReaderTests - + @@ -325,7 +325,7 @@ public class ParticleEffectReaderTests - + @@ -359,7 +359,7 @@ public class ParticleEffectReaderTests - + @@ -391,7 +391,7 @@ public class ParticleEffectReaderTests - + @@ -425,7 +425,7 @@ public class ParticleEffectReaderTests - + @@ -459,7 +459,7 @@ public class ParticleEffectReaderTests - + @@ -498,7 +498,7 @@ public class ParticleEffectReaderTests - + @@ -540,7 +540,7 @@ public class ParticleEffectReaderTests - + @@ -581,7 +581,7 @@ public class ParticleEffectReaderTests - + @@ -622,7 +622,7 @@ public class ParticleEffectReaderTests - + @@ -661,7 +661,7 @@ public class ParticleEffectReaderTests - + @@ -703,7 +703,7 @@ public class ParticleEffectReaderTests - + @@ -744,7 +744,7 @@ public class ParticleEffectReaderTests - + @@ -784,7 +784,7 @@ public class ParticleEffectReaderTests - + @@ -826,7 +826,7 @@ public class ParticleEffectReaderTests - + @@ -866,7 +866,7 @@ public class ParticleEffectReaderTests - + @@ -908,7 +908,7 @@ public class ParticleEffectReaderTests - + @@ -954,7 +954,7 @@ public class ParticleEffectReaderTests - + @@ -1000,7 +1000,7 @@ public class ParticleEffectReaderTests - + @@ -1046,7 +1046,7 @@ public class ParticleEffectReaderTests - + @@ -1092,7 +1092,7 @@ public class ParticleEffectReaderTests - + @@ -1100,7 +1100,7 @@ public class ParticleEffectReaderTests - + @@ -1120,8 +1120,8 @@ public class ParticleEffectReaderTests Assert.Single(modifier.Interpolators); ScaleInterpolator interpolator = Assert.IsType(modifier.Interpolators[0]); - Assert.Equal(0.0f, interpolator.StartValue); - Assert.Equal(0.0f, interpolator.EndValue); + Assert.Equal(Vector2.Zero, interpolator.StartValue); + Assert.Equal(Vector2.One, interpolator.EndValue); } [Fact] @@ -1138,7 +1138,7 @@ public class ParticleEffectReaderTests - + diff --git a/tests/MonoGame.Extended.Tests/Particles/ParticleEffectWriterTests.cs b/tests/MonoGame.Extended.Tests/Particles/ParticleEffectWriterTests.cs index 901b6e59..3f963fc3 100644 --- a/tests/MonoGame.Extended.Tests/Particles/ParticleEffectWriterTests.cs +++ b/tests/MonoGame.Extended.Tests/Particles/ParticleEffectWriterTests.cs @@ -56,7 +56,7 @@ public class ParticleEffectWriterTests - + @@ -90,7 +90,7 @@ public class ParticleEffectWriterTests - + @@ -127,7 +127,7 @@ public class ParticleEffectWriterTests - + @@ -161,7 +161,7 @@ public class ParticleEffectWriterTests - + @@ -195,7 +195,7 @@ public class ParticleEffectWriterTests - + @@ -229,7 +229,7 @@ public class ParticleEffectWriterTests - + @@ -263,7 +263,7 @@ public class ParticleEffectWriterTests - + @@ -297,7 +297,7 @@ public class ParticleEffectWriterTests - + @@ -331,7 +331,7 @@ public class ParticleEffectWriterTests - + @@ -365,7 +365,7 @@ public class ParticleEffectWriterTests - + @@ -399,7 +399,7 @@ public class ParticleEffectWriterTests - + @@ -435,7 +435,7 @@ public class ParticleEffectWriterTests - + @@ -474,7 +474,7 @@ public class ParticleEffectWriterTests - + @@ -513,7 +513,7 @@ public class ParticleEffectWriterTests - + @@ -552,7 +552,7 @@ public class ParticleEffectWriterTests - + @@ -591,7 +591,7 @@ public class ParticleEffectWriterTests - + @@ -630,7 +630,7 @@ public class ParticleEffectWriterTests - + @@ -669,7 +669,7 @@ public class ParticleEffectWriterTests - + @@ -708,7 +708,7 @@ public class ParticleEffectWriterTests - + @@ -747,7 +747,7 @@ public class ParticleEffectWriterTests - + @@ -786,7 +786,7 @@ public class ParticleEffectWriterTests - + @@ -825,7 +825,7 @@ public class ParticleEffectWriterTests - + @@ -866,7 +866,7 @@ public class ParticleEffectWriterTests - + @@ -911,7 +911,7 @@ public class ParticleEffectWriterTests - + @@ -956,7 +956,7 @@ public class ParticleEffectWriterTests - + @@ -1001,7 +1001,7 @@ public class ParticleEffectWriterTests - + @@ -1046,7 +1046,7 @@ public class ParticleEffectWriterTests - + @@ -1054,7 +1054,7 @@ public class ParticleEffectWriterTests - + @@ -1091,7 +1091,7 @@ public class ParticleEffectWriterTests - +