/// <summary>
        /// Updates the <see cref="ICharacterSprite"/>.
        /// </summary>
        /// <param name="currentTime">The current time.</param>
        public void Update(TickCount currentTime)
        {
            if (_skelAnim == null)
            {
                return;
            }

            _skelAnim.Update(currentTime);

            // Update the animation's speed
            if (Character.Velocity.X != 0)
            {
                _skelAnim.Speed = Math.Abs(Character.Velocity.X) / _speedModifier;
            }
            else
            {
                _skelAnim.Speed = 1.0f;
            }
        }
Пример #2
0
        /// <summary>
        /// Handles the Click event of the btnInterpolate control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        void btnInterpolate_Click(object sender, EventArgs e)
        {
            var result = GetLoadSkeletonDialogResult(_filterFrame);

            if (result == null || result.Length <= 1)
                return;

            var frame1Skeleton = SkeletonLoader.LoadSkeleton(result);
            var frame1 = new SkeletonFrame(result, frame1Skeleton, 10);

            result = GetLoadSkeletonDialogResult(_filterFrame);

            if (result == null || result.Length <= 1)
                return;

            var frame2Skeleton = SkeletonLoader.LoadSkeleton(result);
            var frame2 = new SkeletonFrame(result, frame2Skeleton, 10);

            var frames = new[] { frame1, frame2 };

            var ss = new SkeletonSet(frames);
            var sa = new SkeletonAnimation(GetTime(), ss);

            sa.Update(5);
            LoadFrame(sa.Skeleton);
        }
Пример #3
0
        /// <summary>
        /// Updates the skeleton animation.
        /// </summary>
        /// <param name="currentTime">Current time.</param>
        public void Update(TickCount currentTime)
        {
            // If theres no frames and no modifier, don't update
            if (_mod == null && (_skelSet.KeyFrames.Length == 1) && (CurrentFrame.Skeleton == _skelSet.KeyFrames[0].Skeleton))
            {
                _lastTime = currentTime;
            }
            else
            {
                // Find the time that has elapsed since the last update
                float elapsedTime = currentTime - _lastTime;
                _lastTime = currentTime;

                // Calculate the new frame
                float delay;
                if (CurrentFrame.Delay == 0f)
                {
                    delay = NextFrame.Delay;
                }
                else
                {
                    delay = CurrentFrame.Delay;
                }

                var newFrame = _frame + ((elapsedTime * _speed) / delay);
                if (_skelSet.KeyFrames.Length != 1)
                {
                    newFrame %= _skelSet.KeyFrames.Length;
                }

                // Set the new keyframe references if the frame changed
                if ((int)newFrame != (int)_frame)
                {
                    if (_skelSet.KeyFrames.Length == 1)
                    {
                        _nextFrame = _skelSet.KeyFrames[0];
                        _currFrame = _nextFrame;
                    }
                    else
                    {
                        // If we have reached the first frame, raise the OnLoop event
                        if ((int)newFrame == 0)
                        {
                            if (Looped != null)
                            {
                                Looped.Raise(this, EventArgs.Empty);
                            }
                        }

                        // Store the new frame references
                        _currFrame = _skelSet.KeyFrames[(int)newFrame];
                        _nextFrame = _skelSet.KeyFrames[((int)newFrame + 1) % _skelSet.KeyFrames.Length];
                    }
                }

                // Set the new frame
                _frame = newFrame;

                // Update the nodes of the working skeleton
                var          framePercent = _frame - (int)_frame;
                SkeletonNode parentNode;
                if (_parent == null)
                {
                    parentNode = null;
                }
                else
                {
                    parentNode = _parent.Skeleton.RootNode;
                }
                RecursiveUpdate(CurrentFrame.Skeleton.RootNode, NextFrame.Skeleton.RootNode, parentNode, _skel.RootNode,
                                framePercent);
            }

            // Update the body
            if (_skelBody != null)
            {
                _skelBody.Update(currentTime);
            }

            foreach (var bodyLayer in BodyLayers)
            {
                bodyLayer.Update(currentTime);
            }

            // If there is a parent, apply the changes to it
            if (_parent != null)
            {
                RecursiveUpdateParent(_skel.RootNode, _parent.Skeleton.RootNode);
            }

            // Apply the modifiers
            if (_mod != null)
            {
                _mod.Update(currentTime);
            }
        }