Velocity2D ClassDelta Engine Documentation
Component and Update for any Entity moving around in 2D space with velocity limited to a maximum value. It can be accelerated (or decelerated, which is the same) by a vector, by magnitude and direction, or by a scalar factor to its current speed. View code on GitHub
Inheritance Hierarchy

System Object
  DeltaEngine.Physics2D Velocity2D

Namespace: DeltaEngine.Physics2D
Assembly: DeltaEngine.Physics2D (in DeltaEngine.Physics2D.dll) Version: 1.1.1.0 (1.1.1)
Syntax

public class Velocity2D

The Velocity2D type exposes the following members.

Constructors

  NameDescription
Public methodVelocity2D
Initializes a new instance of the Velocity2D class
Top
Remarks

Tests: DeltaEngine.Physics2D.Tests.Velocity2DTests
Examples

7 unit tests call DeltaEngine.Physics2D.Velocity2D
[Test]
public void ApplyUpdateWithVelocity()
{
    var entity2D = new Entity2D(new Rectangle(0, 0, 1, 1));
    entity2D.Add(velocity);
    entity2D.Start<Velocity2D.PositionUpdate>();
    var originalPosition = entity2D.Center;
    entity2D.Get<Velocity2D.Data>().Accelerate(2.0f, 90.0f);
    AdvanceTimeAndUpdateEntities();
    Assert.AreNotEqual(originalPosition, entity2D.Center);
}
[Test]
public void AccelerateByPoint()
{
    velocity.Accelerate(Vector2D.One);
    Assert.AreEqual(Vector2D.One, velocity.Velocity);
}
[Test]
public void AccelerateByPointExceedingMaximum()
{
    velocity.Accelerate(new Vector2D(6, 0));
    Assert.AreEqual(5, velocity.Velocity.X);
    Assert.AreEqual(0, velocity.Velocity.Y);
}
See Also