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 TTransform : GenericTransformation, new()
|
||||||
where TDirection : struct
|
where TDirection : struct
|
||||||
{
|
{
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The amount of particles
|
/// The amount of particles
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,7 @@ namespace SM.Base.Time
|
||||||
{
|
{
|
||||||
base.Ticking(context);
|
base.Ticking(context);
|
||||||
|
|
||||||
ElapsedNormalized = Elapsed / Target;
|
ElapsedNormalized = Math.Min(Elapsed / Target, 1);
|
||||||
if (ElapsedNormalized >= 1) Stopping(context);
|
if (ElapsedNormalized >= 1) Stopping(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,11 @@ namespace SM2D.Drawing
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Vector2? Direction;
|
public Vector2? Direction;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The radius the direction is randomized
|
||||||
|
/// </summary>
|
||||||
|
public float DirectionRadius = 25;
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public DrawParticles(TimeSpan duration) : base(duration)
|
public DrawParticles(TimeSpan duration) : base(duration)
|
||||||
{
|
{
|
||||||
|
|
@ -27,10 +32,20 @@ namespace SM2D.Drawing
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override ParticleStruct<Vector2> CreateObject(int index)
|
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>()
|
return new ParticleStruct<Vector2>()
|
||||||
{
|
{
|
||||||
Matrix = Matrix4.CreateScale(1),
|
Matrix = Matrix4.CreateScale(1),
|
||||||
Direction = Direction.GetValueOrDefault(new Vector2(Randomize.GetFloat(-1, 1), Randomize.GetFloat(-1, 1))),
|
Direction = dir,
|
||||||
Speed = Randomize.GetFloat(MaxSpeed)
|
Speed = Randomize.GetFloat(MaxSpeed)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -36,8 +36,13 @@ namespace SM_TEST
|
||||||
|
|
||||||
window.SetScene(scene = new Scene());
|
window.SetScene(scene = new Scene());
|
||||||
|
|
||||||
DrawText text = new DrawText(font, "Hi, HI");
|
DrawParticles particles = new DrawParticles(TimeSpan.FromSeconds(5))
|
||||||
scene.Objects.Add(text);
|
{
|
||||||
|
Direction = new Vector2(0, 1),
|
||||||
|
DirectionRadius = 10
|
||||||
|
};
|
||||||
|
particles.Trigger();
|
||||||
|
scene.Objects.Add(particles);
|
||||||
|
|
||||||
window.UpdateFrame += WindowOnUpdateFrame;
|
window.UpdateFrame += WindowOnUpdateFrame;
|
||||||
window.RenderFrame += Window_RenderFrame;
|
window.RenderFrame += Window_RenderFrame;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue