Пример #1
0
        // Called when the "Animate" button was clicked.
        private void OnButtonClicked(object sender, EventArgs eventArgs)
        {
            // Get the selected easing function from the DropDownButton.
            EasingFunction easingFunction = (EasingFunction)_functionDropDown.Items[_functionDropDown.SelectedIndex];

            // Set the selected easing mode.
            easingFunction.Mode = (EasingMode)_modeDropDown.Items[_modeDropDown.SelectedIndex];

            // The current slider value:
            float startValue = _slider.Value;

            // Set the slider to the target value.
            _slider.Value = (startValue > 0.5f) ? 0 : 1;

            // Create a from-animation that uses the easing function. It animates the slider
            // value from startValue to the new value.
            SingleFromToByAnimation animation = new SingleFromToByAnimation
            {
                TargetProperty = "Value",
                From           = startValue,
                Duration       = TimeSpan.FromSeconds(1),
                EasingFunction = easingFunction,
                FillBehavior   = FillBehavior.Stop, // Stop the animation when it is finished.
            };

            // Start the animation.
            // (Use the Replace transition to replace any currently running animations.
            // This is necessary because the user could press the Animate button while
            // an animation is running.)
            _animationService.StartAnimation(animation, _slider, AnimationTransitions.Replace())
            .UpdateAndApply();             // Apply new animation value immediately.
        }
Пример #2
0
        public void PlayAnimation(string name)
        {
            if (CurrentAnimation == name)
            {
                return;
            }

            StopAnimation();

            CurrentAnimation = name;

            // Start selected animation.
            var meshNode         = ModelNode.GetDescendants().OfType <MeshNode>().First();
            var mesh             = meshNode.Mesh;
            var animation        = mesh.Animations[name];
            var loopingAnimation = new TimelineClip(animation)
            {
                Duration     = TimeSpan.MaxValue,
                LoopBehavior = LoopBehavior.Cycle,
            };

            _animationController = _animationService.StartAnimation(loopingAnimation, (IAnimatableProperty)meshNode.SkeletonPose);

            // Update view model IsPlaying flags.
            foreach (var animationPropertyViewModel in _animationPropertyViewModels)
            {
                if (animationPropertyViewModel.Name == CurrentAnimation)
                {
                    animationPropertyViewModel.IsPlaying = true;
                }
            }
        }
Пример #3
0
        protected override void OnLoad()
        {
            base.OnLoad();

            // Call Measure to update DesiredWith and DesiredHeight.
            Measure(new Vector2F(float.PositiveInfinity));

            // Set a random position on the screen where the whole window is visible and to the right
            // of the MainScreenComponent buttons.
            X = RandomHelper.Random.NextInteger(200, (int)(Screen.ActualWidth - DesiredWidth));
            Y = RandomHelper.Random.NextInteger(0, (int)(Screen.ActualHeight - DesiredHeight));

            if (LoadingAnimation != null)
            {
                // Start the animation.
                var animationController = _animationService.StartAnimation(LoadingAnimation, this);

                // Note: The animation effectively starts when AnimationManager.Update() and Apply() are
                // called. To start the animation immediately we can call UpdateAndApply() manually.
                animationController.UpdateAndApply();
            }
        }