Exemplo n.º 1
0
        /// <summary>
        /// Updates the <see cref="CurrentFrame"/>, <see cref="NextFrame"/> and <see cref="CurrentFrameProgress"/> properties immediately.
        /// This is called implicitly once each frame before drawing, so you don't normally call this. However, when changing animation
        /// parameters and requiring updated animation frame data immediately, this could be helpful.
        /// </summary>
        public void UpdateVisibleFrames()
        {
            // Calculate visible frames
            curAnimFrame     = 0;
            nextAnimFrame    = 0;
            curAnimFrameFade = 0.0f;
            if (animFrameCount > 0 && animDuration > 0)
            {
                // Calculate currently visible frame
                float frameTemp = animFrameCount * animTime / animDuration;
                curAnimFrame = (int)frameTemp;

                // Normalize current frame when exceeding anim duration
                if (animLoopMode == LoopMode.Once || animLoopMode == LoopMode.FixedSingle)
                {
                    curAnimFrame = MathF.Clamp(curAnimFrame, 0, animFrameCount - 1);
                }
                else
                {
                    curAnimFrame = MathF.NormalizeVar(curAnimFrame, 0, animFrameCount);
                }

                // Calculate second frame and fade value
                curAnimFrameFade = frameTemp - (int)frameTemp;
                if (animLoopMode == LoopMode.Loop)
                {
                    nextAnimFrame = MathF.NormalizeVar(curAnimFrame + 1, 0, animFrameCount);
                }
                else
                {
                    nextAnimFrame = curAnimFrame + 1;
                }
            }
            curAnimFrame  = animFirstFrame + MathF.Clamp(curAnimFrame, 0, animFrameCount - 1);
            nextAnimFrame = animFirstFrame + MathF.Clamp(nextAnimFrame, 0, animFrameCount - 1);
        }