public override void Update(GameTime gameTime)
        {
            // <Up> --> Increase blend weight of first animation.
            if (InputService.IsDown(Keys.Up))
            {
                float weight = _blendedAnimation.GetWeight(0);

                weight += 1 * (float)gameTime.ElapsedGameTime.TotalSeconds;
                if (weight > 1)
                {
                    weight = 1;
                }

                _blendedAnimation.SetWeight(0, weight);
                _blendedAnimation.SetWeight(1, 1 - weight);
            }

            // <Down> --> Increase blend weight of second animation.
            if (InputService.IsDown(Keys.Down))
            {
                float weight = _blendedAnimation.GetWeight(0);

                weight -= 1 * (float)gameTime.ElapsedGameTime.TotalSeconds;
                if (weight < 0)
                {
                    weight = 0;
                }

                _blendedAnimation.SetWeight(0, weight);
                _blendedAnimation.SetWeight(1, 1 - weight);
            }


            base.Update(gameTime);
        }
예제 #2
0
        public void BlendGroupWithTwoAnimationsSynchronized()
        {
            var property1 = new AnimatableProperty <float> {
                Value = 123.45f
            };

            var blendGroup = new BlendGroup {
                FillBehavior = FillBehavior.Stop
            };
            var animation1 = new SingleFromToByAnimation {
                From = 0, To = 100, Duration = TimeSpan.FromSeconds(1.0)
            };
            var animation2 = new SingleFromToByAnimation {
                From = 100, To = 300, Duration = TimeSpan.FromSeconds(2.0)
            };

            blendGroup.Add(animation1);
            blendGroup.Add(animation2);
            Assert.AreEqual(1.0f, blendGroup.GetWeight(0));
            Assert.AreEqual(1.0f, blendGroup.GetWeight(1));
            Assert.AreEqual(TimeSpan.FromSeconds(2.0), blendGroup.GetTotalDuration());

            blendGroup.SynchronizeDurations();
            Assert.AreEqual(TimeSpan.FromSeconds(1.5), blendGroup.GetTotalDuration());

            var manager    = new AnimationManager();
            var controller = manager.StartAnimation(blendGroup, property1);

            controller.UpdateAndApply();
            Assert.AreEqual(50.0f, property1.Value);

            manager.Update(TimeSpan.FromSeconds(0.75)); // t = 0.75
            manager.ApplyAnimations();
            Assert.AreEqual(TimeSpan.FromSeconds(1.5), blendGroup.GetTotalDuration());
            Assert.AreEqual(0.5f * 50.0f + 0.5f * 200.0f, property1.Value);

            blendGroup.SetWeight(0, 0);
            Assert.AreEqual(TimeSpan.FromSeconds(2.0), blendGroup.GetTotalDuration());
            manager.Update(TimeSpan.FromSeconds(0.25)); // t = 1.0
            manager.ApplyAnimations();
            Assert.AreEqual(200.0f, property1.Value);

            blendGroup.SetWeight(0, 10);
            blendGroup.SetWeight(1, 0);
            Assert.AreEqual(TimeSpan.FromSeconds(1.0), blendGroup.GetTotalDuration());
            manager.Update(TimeSpan.Zero); // t = 1.0
            manager.ApplyAnimations();
            Assert.AreEqual(100.0f, property1.Value);

            blendGroup.SetWeight(0, 10);
            blendGroup.SetWeight(1, 1);
            Assert.AreEqual(new TimeSpan((long)((1.0f * 10.0f / 11.0f + 2.0f * 1.0f / 11.0f) * TimeSpan.TicksPerSecond)), blendGroup.GetTotalDuration());
            manager.Update(TimeSpan.FromSeconds(0.5)); // t = 1.5
            manager.ApplyAnimations();
            Assert.AreEqual(123.45f, property1.Value);
            Assert.AreEqual(AnimationState.Stopped, controller.State);
        }
예제 #3
0
        public void BlendGroupWithOneAnimation()
        {
            var property1 = new AnimatableProperty <float> {
                Value = 123.45f
            };

            var blendGroup = new BlendGroup {
                FillBehavior = FillBehavior.Stop
            };
            var animation = new SingleFromToByAnimation {
                From = 0, To = 100, Duration = TimeSpan.FromSeconds(1.0)
            };

            blendGroup.Add(animation);
            Assert.AreEqual(1.0f, blendGroup.GetWeight(0));
            Assert.AreEqual(1.0f, blendGroup.GetWeight(animation));

            blendGroup.SetWeight(0, 10.0f);
            Assert.AreEqual(10.0f, blendGroup.GetWeight(0));
            Assert.AreEqual(10.0f, blendGroup.GetWeight(animation));

            blendGroup.SetWeight(animation, 0.5f);
            Assert.AreEqual(0.5f, blendGroup.GetWeight(0));
            Assert.AreEqual(0.5f, blendGroup.GetWeight(animation));

            var manager    = new AnimationManager();
            var controller = manager.StartAnimation(blendGroup, property1);

            controller.UpdateAndApply();
            Assert.AreEqual(0.0f, property1.Value);

            manager.Update(TimeSpan.FromSeconds(0.25));
            manager.ApplyAnimations();
            Assert.AreEqual(25.0f, property1.Value);

            manager.Update(TimeSpan.FromSeconds(0.25));
            manager.ApplyAnimations();
            Assert.AreEqual(50.0f, property1.Value);

            manager.Update(TimeSpan.FromSeconds(0.25));
            manager.ApplyAnimations();
            Assert.AreEqual(75.0f, property1.Value);

            manager.Update(TimeSpan.FromSeconds(0.25));
            manager.ApplyAnimations();
            Assert.AreEqual(100.0f, property1.Value);

            manager.Update(TimeSpan.FromSeconds(0.25));
            manager.ApplyAnimations();
            Assert.AreEqual(123.45f, property1.Value);
            Assert.AreEqual(AnimationState.Stopped, controller.State);
        }
예제 #4
0
        public void BlendGroupWithAnimationAndTimelineGroups()
        {
            var testObject = new AnimatableObject("TestObject");
              var property1 = new AnimatableProperty<float> { Value = 123.45f };
              testObject.Properties.Add("Property1", property1);

              var blendGroup = new BlendGroup
              {
            new SingleFromToByAnimation { From = 0, To = 100, TargetProperty = "Property1" },
            new TimelineGroup { new SingleFromToByAnimation { From = 100, To = 300, Duration = TimeSpan.FromSeconds(2.0), TargetProperty = "Property1" }, },
              };
              blendGroup.SynchronizeDurations();
              Assert.AreEqual(TimeSpan.FromSeconds(1.5), blendGroup.GetTotalDuration());

              var manager = new AnimationManager();
              var controller = manager.StartAnimation(blendGroup, testObject);
              controller.UpdateAndApply();
              Assert.AreEqual(50.0f, property1.Value);

              manager.Update(TimeSpan.FromSeconds(0.75));      // t = 0.75
              manager.ApplyAnimations();
              Assert.AreEqual(TimeSpan.FromSeconds(1.5), blendGroup.GetTotalDuration());
              Assert.AreEqual(0.5f * 50.0f + 0.5f * 200.0f, property1.Value);

              blendGroup.SetWeight(0, 0);
              Assert.AreEqual(TimeSpan.FromSeconds(2.0), blendGroup.GetTotalDuration());
              manager.Update(TimeSpan.FromSeconds(0.25));       // t = 1.0
              manager.ApplyAnimations();
              Assert.AreEqual(200.0f, property1.Value);

              blendGroup.SetWeight(0, 10);
              blendGroup.SetWeight(1, 0);
              Assert.AreEqual(TimeSpan.FromSeconds(1.0), blendGroup.GetTotalDuration());
              manager.Update(TimeSpan.Zero);       // t = 1.0
              manager.ApplyAnimations();
              Assert.AreEqual(100.0f, property1.Value);

              blendGroup.SetWeight(0, 10);
              blendGroup.SetWeight(1, 1);
              Assert.AreEqual(new TimeSpan((long)((1.0f * 10.0f / 11.0f + 2.0f * 1.0f / 11.0f) * TimeSpan.TicksPerSecond)), blendGroup.GetTotalDuration());
              manager.Update(TimeSpan.FromSeconds(0.5));       // t = 1.5
              manager.ApplyAnimations();
              Assert.AreEqual(AnimationState.Filling, controller.State);
              Assert.IsTrue(Numeric.AreEqual(100.0f * 10.0f / 11.0f + 300.0f * 1.0f / 11.0f, property1.Value));

              controller.Stop();
              controller.UpdateAndApply();
              Assert.AreEqual(AnimationState.Stopped, controller.State);
              Assert.AreEqual(123.45f, property1.Value);
        }
예제 #5
0
        public void BlendGroupWithOneAnimation()
        {
            var property1 = new AnimatableProperty<float> { Value = 123.45f };

              var blendGroup = new BlendGroup { FillBehavior = FillBehavior.Stop };
              var animation = new SingleFromToByAnimation { From = 0, To = 100, Duration = TimeSpan.FromSeconds(1.0) };
              blendGroup.Add(animation);
              Assert.AreEqual(1.0f, blendGroup.GetWeight(0));
              Assert.AreEqual(1.0f, blendGroup.GetWeight(animation));

              blendGroup.SetWeight(0, 10.0f);
              Assert.AreEqual(10.0f, blendGroup.GetWeight(0));
              Assert.AreEqual(10.0f, blendGroup.GetWeight(animation));

              blendGroup.SetWeight(animation, 0.5f);
              Assert.AreEqual(0.5f, blendGroup.GetWeight(0));
              Assert.AreEqual(0.5f, blendGroup.GetWeight(animation));

              var manager = new AnimationManager();
              var controller = manager.StartAnimation(blendGroup, property1);
              controller.UpdateAndApply();
              Assert.AreEqual(0.0f, property1.Value);

              manager.Update(TimeSpan.FromSeconds(0.25));
              manager.ApplyAnimations();
              Assert.AreEqual(25.0f, property1.Value);

              manager.Update(TimeSpan.FromSeconds(0.25));
              manager.ApplyAnimations();
              Assert.AreEqual(50.0f, property1.Value);

              manager.Update(TimeSpan.FromSeconds(0.25));
              manager.ApplyAnimations();
              Assert.AreEqual(75.0f, property1.Value);

              manager.Update(TimeSpan.FromSeconds(0.25));
              manager.ApplyAnimations();
              Assert.AreEqual(100.0f, property1.Value);

              manager.Update(TimeSpan.FromSeconds(0.25));
              manager.ApplyAnimations();
              Assert.AreEqual(123.45f, property1.Value);
              Assert.AreEqual(AnimationState.Stopped, controller.State);
        }
예제 #6
0
        public void ShouldDoNothingWhenWeightsAreZero()
        {
            var blendGroup = new BlendGroup {
                FillBehavior = FillBehavior.Stop
            };
            var animation1 = new SingleFromToByAnimation {
                From = 0, To = 100, Duration = TimeSpan.FromSeconds(1.0)
            };
            var animation2 = new SingleFromToByAnimation {
                From = 100, To = 300, Duration = TimeSpan.FromSeconds(2.0)
            };

            blendGroup.Add(animation1);
            blendGroup.Add(animation2);
            blendGroup.SetWeight(0, 0);
            blendGroup.SetWeight(1, 0);

            Assert.That(() => blendGroup.SynchronizeDurations(), Throws.Nothing);
            blendGroup.Update();
            Assert.AreEqual(0.0f, blendGroup.GetNormalizedWeight(0));
            Assert.AreEqual(0.0f, blendGroup.GetNormalizedWeight(1));
        }
예제 #7
0
        public void EmptyBlendGroup()
        {
            var property1  = new AnimatableProperty <float>();
            var blendGroup = new BlendGroup();

            Assert.That(() => blendGroup.GetWeight(0), Throws.TypeOf <ArgumentOutOfRangeException>());
            Assert.That(() => blendGroup.SetWeight(0, 1.0f), Throws.TypeOf <ArgumentOutOfRangeException>());

            var manager    = new AnimationManager();
            var controller = manager.StartAnimation(blendGroup, property1);

            manager.Update(TimeSpan.Zero);
            manager.ApplyAnimations();
            Assert.AreEqual(AnimationState.Stopped, controller.State);

            blendGroup.SynchronizeDurations();
            blendGroup.Clear();
            controller = manager.StartAnimation(blendGroup, property1);
            manager.Update(TimeSpan.Zero);
            manager.ApplyAnimations();
            Assert.AreEqual(AnimationState.Stopped, controller.State);
        }
예제 #8
0
        public void BlendGroupWithAnimationAndTimelineGroups()
        {
            var testObject = new AnimatableObject("TestObject");
            var property1  = new AnimatableProperty <float> {
                Value = 123.45f
            };

            testObject.Properties.Add("Property1", property1);

            var blendGroup = new BlendGroup
            {
                new SingleFromToByAnimation {
                    From = 0, To = 100, TargetProperty = "Property1"
                },
                new TimelineGroup {
                    new SingleFromToByAnimation {
                        From = 100, To = 300, Duration = TimeSpan.FromSeconds(2.0), TargetProperty = "Property1"
                    },
                },
            };

            blendGroup.SynchronizeDurations();
            Assert.AreEqual(TimeSpan.FromSeconds(1.5), blendGroup.GetTotalDuration());

            var manager    = new AnimationManager();
            var controller = manager.StartAnimation(blendGroup, testObject);

            controller.UpdateAndApply();
            Assert.AreEqual(50.0f, property1.Value);

            manager.Update(TimeSpan.FromSeconds(0.75)); // t = 0.75
            manager.ApplyAnimations();
            Assert.AreEqual(TimeSpan.FromSeconds(1.5), blendGroup.GetTotalDuration());
            Assert.AreEqual(0.5f * 50.0f + 0.5f * 200.0f, property1.Value);

            blendGroup.SetWeight(0, 0);
            Assert.AreEqual(TimeSpan.FromSeconds(2.0), blendGroup.GetTotalDuration());
            manager.Update(TimeSpan.FromSeconds(0.25)); // t = 1.0
            manager.ApplyAnimations();
            Assert.AreEqual(200.0f, property1.Value);

            blendGroup.SetWeight(0, 10);
            blendGroup.SetWeight(1, 0);
            Assert.AreEqual(TimeSpan.FromSeconds(1.0), blendGroup.GetTotalDuration());
            manager.Update(TimeSpan.Zero); // t = 1.0
            manager.ApplyAnimations();
            Assert.AreEqual(100.0f, property1.Value);

            blendGroup.SetWeight(0, 10);
            blendGroup.SetWeight(1, 1);
            Assert.AreEqual(new TimeSpan((long)((1.0f * 10.0f / 11.0f + 2.0f * 1.0f / 11.0f) * TimeSpan.TicksPerSecond)), blendGroup.GetTotalDuration());
            manager.Update(TimeSpan.FromSeconds(0.5)); // t = 1.5
            manager.ApplyAnimations();
            Assert.AreEqual(AnimationState.Filling, controller.State);
            Assert.IsTrue(Numeric.AreEqual(100.0f * 10.0f / 11.0f + 300.0f * 1.0f / 11.0f, property1.Value));

            controller.Stop();
            controller.UpdateAndApply();
            Assert.AreEqual(AnimationState.Stopped, controller.State);
            Assert.AreEqual(123.45f, property1.Value);
        }
예제 #9
0
        public void ShouldDoNothingWhenWeightsAreZero()
        {
            var blendGroup = new BlendGroup { FillBehavior = FillBehavior.Stop };
              var animation1 = new SingleFromToByAnimation { From = 0, To = 100, Duration = TimeSpan.FromSeconds(1.0) };
              var animation2 = new SingleFromToByAnimation { From = 100, To = 300, Duration = TimeSpan.FromSeconds(2.0) };
              blendGroup.Add(animation1);
              blendGroup.Add(animation2);
              blendGroup.SetWeight(0, 0);
              blendGroup.SetWeight(1, 0);

              Assert.That(() => blendGroup.SynchronizeDurations(), Throws.Nothing);
              blendGroup.Update();
              Assert.AreEqual(0.0f, blendGroup.GetNormalizedWeight(0));
              Assert.AreEqual(0.0f, blendGroup.GetNormalizedWeight(1));
        }
예제 #10
0
        public void EmptyBlendGroup()
        {
            var property1 = new AnimatableProperty<float>();
              var blendGroup = new BlendGroup();

              Assert.That(() => blendGroup.GetWeight(0), Throws.TypeOf<ArgumentOutOfRangeException>());
              Assert.That(() => blendGroup.SetWeight(0, 1.0f), Throws.TypeOf<ArgumentOutOfRangeException>());

              var manager = new AnimationManager();
              var controller = manager.StartAnimation(blendGroup, property1);
              manager.Update(TimeSpan.Zero);
              manager.ApplyAnimations();
              Assert.AreEqual(AnimationState.Stopped, controller.State);

              blendGroup.SynchronizeDurations();
              blendGroup.Clear();
              controller = manager.StartAnimation(blendGroup, property1);
              manager.Update(TimeSpan.Zero);
              manager.ApplyAnimations();
              Assert.AreEqual(AnimationState.Stopped, controller.State);
        }
예제 #11
0
        public void BlendGroupWithTwoAnimationsSynchronized()
        {
            var property1 = new AnimatableProperty<float> { Value = 123.45f };

              var blendGroup = new BlendGroup { FillBehavior = FillBehavior.Stop };
              var animation1 = new SingleFromToByAnimation { From = 0, To = 100, Duration = TimeSpan.FromSeconds(1.0) };
              var animation2 = new SingleFromToByAnimation { From = 100, To = 300, Duration = TimeSpan.FromSeconds(2.0) };
              blendGroup.Add(animation1);
              blendGroup.Add(animation2);
              Assert.AreEqual(1.0f, blendGroup.GetWeight(0));
              Assert.AreEqual(1.0f, blendGroup.GetWeight(1));
              Assert.AreEqual(TimeSpan.FromSeconds(2.0), blendGroup.GetTotalDuration());

              blendGroup.SynchronizeDurations();
              Assert.AreEqual(TimeSpan.FromSeconds(1.5), blendGroup.GetTotalDuration());

              var manager = new AnimationManager();
              var controller = manager.StartAnimation(blendGroup, property1);
              controller.UpdateAndApply();
              Assert.AreEqual(50.0f, property1.Value);

              manager.Update(TimeSpan.FromSeconds(0.75));      // t = 0.75
              manager.ApplyAnimations();
              Assert.AreEqual(TimeSpan.FromSeconds(1.5), blendGroup.GetTotalDuration());
              Assert.AreEqual(0.5f * 50.0f + 0.5f * 200.0f, property1.Value);

              blendGroup.SetWeight(0, 0);
              Assert.AreEqual(TimeSpan.FromSeconds(2.0), blendGroup.GetTotalDuration());
              manager.Update(TimeSpan.FromSeconds(0.25));       // t = 1.0
              manager.ApplyAnimations();
              Assert.AreEqual(200.0f, property1.Value);

              blendGroup.SetWeight(0, 10);
              blendGroup.SetWeight(1, 0);
              Assert.AreEqual(TimeSpan.FromSeconds(1.0), blendGroup.GetTotalDuration());
              manager.Update(TimeSpan.Zero);       // t = 1.0
              manager.ApplyAnimations();
              Assert.AreEqual(100.0f, property1.Value);

              blendGroup.SetWeight(0, 10);
              blendGroup.SetWeight(1, 1);
              Assert.AreEqual(new TimeSpan((long)((1.0f * 10.0f / 11.0f + 2.0f * 1.0f / 11.0f) * TimeSpan.TicksPerSecond)), blendGroup.GetTotalDuration());
              manager.Update(TimeSpan.FromSeconds(0.5));       // t = 1.5
              manager.ApplyAnimations();
              Assert.AreEqual(123.45f, property1.Value);
              Assert.AreEqual(AnimationState.Stopped, controller.State);
        }