Example #1
0
        public virtual void Update(GameTime gameTime)
        {
            // Scale the button based on animation state
            switch (animationState)
            {
            case ButtonAnimationState.Idle: break;

            case ButtonAnimationState.Pressing:
                scaleTimeElapsed += gameTime.ElapsedGameTime;
                scale.X           = (float)Tween.BounceEaseOut(scaleTimeElapsed.TotalMilliseconds, 1, -0.25, scaleDuration.TotalMilliseconds);
                scale.Y           = (float)Tween.BounceEaseOut(scaleTimeElapsed.TotalMilliseconds, 1, -0.25, scaleDuration.TotalMilliseconds);
                if (scaleTimeElapsed >= scaleDuration)
                {
                    animationState = ButtonAnimationState.Idle;
                }
                break;

            case ButtonAnimationState.Releasing:
                scaleTimeElapsed += gameTime.ElapsedGameTime;
                scale.X           = (float)Tween.BounceEaseOut(scaleTimeElapsed.TotalMilliseconds, 0.75, 0.25, scaleDuration.TotalMilliseconds);
                scale.Y           = (float)Tween.BounceEaseOut(scaleTimeElapsed.TotalMilliseconds, 0.75, 0.25, scaleDuration.TotalMilliseconds);
                if (scaleTimeElapsed >= scaleDuration)
                {
                    animationState = ButtonAnimationState.Idle;
                }
                break;
            }

            // Make the button pulse
            scale.X += (float)Math.Cos(gameTime.TotalGameTime.TotalSeconds * 4) / 500;
            scale.Y += (float)Math.Sin(gameTime.TotalGameTime.TotalSeconds * 4) / 500;
        }