Пример #1
0
        //-------------------------------------------------------------------------------
        //This is allow us to select the animation sequence without playing it.
        //-------------------------------------------------------------------------------
        public void SetSequence(string szSequence)
        {
            AnimationDescription desc;

            Debug.Assert(m_animations.TryGetValue(szSequence, out desc), "Animation " + szSequence + " doesn't exist!!!");

            m_currentAnimation = desc;
            Paused             = true;
        }
Пример #2
0
        //-------------------------------------------------------------------------------
        //-------------------------------------------------------------------------------
        public void PlayAnimation(string szAnimationName)
        {
            AnimationDescription desc;

            Debug.Assert(m_animations.TryGetValue(szAnimationName, out desc), "Animation " + szAnimationName + " doesn't exist!!!");

            m_currentAnimation            = desc;
            m_fTimeElapsedScinceLastFrame = 0.0f;
            Paused = false;
        }
Пример #3
0
        public SpriteAnimation(List <AnimationDescription> animations)
        {
            m_currentFrame       = Frame.Zero;
            m_currentAnimation   = null;
            m_animations         = new Dictionary <string, AnimationDescription>(20);
            IsDisposed           = false;
            Direction            = AnimationDirection.Forward;
            DesiredAnimationRate = 10.0f;

            Debug.Assert(animations.Count < 20, "There is more than 20 animations");

            foreach (AnimationDescription desc in animations)
            {
                m_animations.Add(desc.m_szName, desc);
            }
        }
Пример #4
0
        //-------------------------------------------------------------------------------
        //-------------------------------------------------------------------------------
        public SpriteAnimationData UpdateCurrentAnimation(DeltaTime deltaTime)
        {
            SpriteAnimationData data = new SpriteAnimationData();

            if (m_currentAnimation != null && !Paused)
            {
                m_fTimeElapsedScinceLastFrame += deltaTime.ElapsedGameTime.TotalMilliseconds;

                if (m_fTimeElapsedScinceLastFrame >= m_fDesiredElapsedTime)
                {
                    data.m_currentFrame.X         = Direction == AnimationDirection.Forward ? m_currentFrame.X++ : m_currentFrame.X--;
                    m_fTimeElapsedScinceLastFrame = 0;
                }
                else
                {
                    data.m_currentFrame.X = m_currentFrame.X;
                }

                data.m_currentFrame.Y = m_currentFrame.Y;
                data.m_frameSize      = m_currentAnimation.m_frameSize;

                if ((m_currentFrame.X * m_currentAnimation.m_frameSize.X) >= m_currentAnimation.m_sheetSize.X)
                {
                    if (m_currentAnimation.m_bLooping)
                    {
                        m_currentFrame = Frame.Zero;
                    }
                    else
                    {
                        m_currentAnimation = null;
                    }
                }
            }
            //We need to do this if it is paused with an animation.
            else if (m_currentAnimation != null && Paused)
            {
                data.m_currentFrame = m_currentFrame;
                data.m_frameSize    = m_currentAnimation.m_frameSize;
            }

            return(data);
        }