예제 #1
0
        public void InterpolateStoppedTest()
        {
            var e = new TestEntity();
            var i = new EntityInterpolator();

            e.Position = new Vector2(0);
            i.Update(e, 1);
            Assert.AreEqual(Vector2.Zero, i.DrawPosition);

            e.Move(new Vector2(16));
            e.SetVelocity(new Vector2(1));
            i.Update(e, 1);
            Assert.AreNotEqual(new Vector2(0), i.DrawPosition);

            e.Move(new Vector2(100));
            e.SetVelocity(new Vector2(0));
            i.Update(e, 1);
            Assert.AreNotEqual(new Vector2(16), i.DrawPosition);

            var last = i.DrawPosition;

            e.Move(new Vector2(50));
            i.Update(e, 10);
            Assert.AreNotEqual(last, i.DrawPosition);
        }
예제 #2
0
        public void InterpolateNoVelocityRecordTest()
        {
            var e = new TestEntity();
            var i = new EntityInterpolator();

            e.Position = new Vector2(0);
            i.Update(e, 1);
            Assert.AreEqual(Vector2.Zero, i.DrawPosition);

            e.Move(new Vector2(16));
            i.Update(e, 1);
            Assert.AreEqual(new Vector2(16), i.DrawPosition);

            e.Move(new Vector2(100));
            i.Update(e, 1);
            Assert.AreEqual(new Vector2(116), i.DrawPosition);
        }
예제 #3
0
        /// <summary>
        /// Handles updating this <see cref="Entity"/>.
        /// </summary>
        /// <param name="imap">The map the <see cref="Entity"/> is on.</param>
        /// <param name="deltaTime">The amount of time (in milliseconds) that has elapsed since the last update.</param>
        protected override void HandleUpdate(IMap imap, int deltaTime)
        {
            base.HandleUpdate(imap, deltaTime);

            // Get the delta time
            var currentTime    = GetTime();
            var lastDrawnDelta = Math.Min(currentTime - _lastDrawnTime, GameData.MaxDrawDeltaTime);

            _lastDrawnTime = currentTime;

            // Update the sprite
            _characterSprite.Update(currentTime);

            UpdateAnimation();

            // Update the interpolation
            _interpolator.Update(this, (int)lastDrawnDelta);
        }