Exemplo n.º 1
0
        /// <summary>
        /// Change the current animation to the specified animation.
        /// </summary>
        /// <param name="name">The unique identifier of the animation.</param>
        private void ChangeAnimation(string name)
        {
            if (String.IsNullOrEmpty(name))
            {
                name = "idle";
            }
            if (!_animationData.TryGetValue(name, out ComplexAnimData animData))
            {
                return;

                throw new Exception("Animation not found.");
            }

            if (name == _currentName)
            {
                return;
            }

            // Reset animation and change current animation being used.
            _currentFrame = 0;
            _frameTimer.Reset();
            _currentAnimationData = animData;
            _currentName          = name;

            // Switch to the new texture and size.
            _texture = _currentAnimationData.Texture;
            _sourceRectangle.Width  = _currentAnimationData.Width;
            _sourceRectangle.Height = _currentAnimationData.Height;
            _sourceRectangle.Y      = _currentAnimationData.StartingY;

            AnimationStateChanged?.Invoke();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Add an animation data to the list of avalaible ADs.
        /// </summary>
        /// <param name="name">The unique name that identifies this data.</param>
        /// <param name="data">The data that is linked to that name.</param>
        public void AddAnimationData(string name, ComplexAnimData data)
        {
            // Check to see if identifier already exists.
            if (_animationData.TryGetValue(name, out ComplexAnimData value))
            {
                throw new Exception("Identifier for this animation data already exists.");
            }

            _animationData.Add(name, data);
        }