Added DirectionalParticles and fixed the ElapsedNormalized of Timer.
This commit is contained in:
parent
01998d78dc
commit
6cb1fea19a
4 changed files with 25 additions and 4 deletions
|
|
@ -18,6 +18,7 @@ namespace SM.Base.Drawing.Particles
|
|||
where TTransform : GenericTransformation, new()
|
||||
where TDirection : struct
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// The amount of particles
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ namespace SM.Base.Time
|
|||
{
|
||||
base.Ticking(context);
|
||||
|
||||
ElapsedNormalized = Elapsed / Target;
|
||||
ElapsedNormalized = Math.Min(Elapsed / Target, 1);
|
||||
if (ElapsedNormalized >= 1) Stopping(context);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,6 +19,11 @@ namespace SM2D.Drawing
|
|||
/// </summary>
|
||||
public Vector2? Direction;
|
||||
|
||||
/// <summary>
|
||||
/// The radius the direction is randomized
|
||||
/// </summary>
|
||||
public float DirectionRadius = 25;
|
||||
|
||||
/// <inheritdoc />
|
||||
public DrawParticles(TimeSpan duration) : base(duration)
|
||||
{
|
||||
|
|
@ -27,10 +32,20 @@ namespace SM2D.Drawing
|
|||
/// <inheritdoc />
|
||||
protected override ParticleStruct<Vector2> CreateObject(int index)
|
||||
{
|
||||
Vector2 dir;
|
||||
if (Direction.HasValue)
|
||||
{
|
||||
Vector2 direction = Direction.Value;
|
||||
|
||||
dir = (new Vector4(direction.X, direction.Y, 1, 1) *
|
||||
Matrix4.CreateRotationZ(MathHelper.DegreesToRadians(Randomize.GetFloat(-DirectionRadius / 2, DirectionRadius / 2)))).Xy;
|
||||
}
|
||||
else dir = new Vector2(Randomize.GetFloat(-1, 1), Randomize.GetFloat(-1, 1));
|
||||
|
||||
return new ParticleStruct<Vector2>()
|
||||
{
|
||||
Matrix = Matrix4.CreateScale(1),
|
||||
Direction = Direction.GetValueOrDefault(new Vector2(Randomize.GetFloat(-1, 1), Randomize.GetFloat(-1, 1))),
|
||||
Direction = dir,
|
||||
Speed = Randomize.GetFloat(MaxSpeed)
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue