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;
        }
Example #2
0
        private static void Initialize()
        {
            int assetWidth  = 253;
            int assetHeight = 64;

            RoomButtonPresets = new Dictionary <PlayerStatus, Dictionary <GameMode, ButtonPreset> >();

            for (int userStatus = 0; userStatus < 4; userStatus++)
            {
                PlayerStatus roS = (PlayerStatus)userStatus;
                Dictionary <GameMode, ButtonPreset> buttonPreset = new Dictionary <GameMode, ButtonPreset>();
                RoomButtonPresets.Add(roS, buttonPreset);

                for (int gameMode = 0; gameMode < 4; gameMode++)
                {
                    Dictionary <ButtonAnimationState, Rectangle> statePreset = new Dictionary <ButtonAnimationState, Rectangle>();

                    for (int buttonAState = 0; buttonAState < 3; buttonAState++)
                    {
                        ButtonAnimationState bAS = (ButtonAnimationState)buttonAState;

                        Rectangle rect = new Rectangle(assetWidth * (3 * gameMode + buttonAState), assetHeight * userStatus, assetWidth, assetHeight);
                        statePreset.Add(bAS, rect);
                    }

                    buttonPreset.Add((GameMode)gameMode, new ButtonPreset()
                    {
                        SpritePath  = "Interface/StaticButtons/GameList/Background",
                        StatePreset = statePreset
                    });
                }
            }
        }
Example #3
0
        public virtual void HandleInput(GameTime gameTime)
        {
            if (screen.ScreenManager.Game.InputManager.LeftButtonPressed && rectangle.Contains(screen.ScreenManager.Game.InputManager.WorldPosition.X, screen.ScreenManager.Game.InputManager.WorldPosition.Y))
            {
                pressed          = true;
                animationState   = ButtonAnimationState.Pressing;
                scaleTimeElapsed = TimeSpan.Zero;
            }

            if (pressed && !rectangle.Contains(screen.ScreenManager.Game.InputManager.WorldPosition.X, screen.ScreenManager.Game.InputManager.WorldPosition.Y))
            {
                pressed          = false;
                animationState   = ButtonAnimationState.Releasing;
                scaleTimeElapsed = TimeSpan.Zero;
            }

            if (pressed && screen.ScreenManager.Game.InputManager.LeftButtonReleased && rectangle.Contains(screen.ScreenManager.Game.InputManager.WorldPosition.X, screen.ScreenManager.Game.InputManager.WorldPosition.Y))
            {
                OnSelect();
                pressed          = false;
                animationState   = ButtonAnimationState.Releasing;
                scaleTimeElapsed = TimeSpan.Zero;
            }
        }
Example #4
0
        public virtual void HandleInput(GameTime gameTime)
        {
            if(screen.ScreenManager.Game.InputManager.LeftButtonPressed && rectangle.Contains(screen.ScreenManager.Game.InputManager.WorldPosition.X, screen.ScreenManager.Game.InputManager.WorldPosition.Y))
            {
                pressed = true;
                animationState = ButtonAnimationState.Pressing;
                scaleTimeElapsed = TimeSpan.Zero;
            }

            if (pressed && !rectangle.Contains(screen.ScreenManager.Game.InputManager.WorldPosition.X, screen.ScreenManager.Game.InputManager.WorldPosition.Y))
            {
                pressed = false;
                animationState = ButtonAnimationState.Releasing;
                scaleTimeElapsed = TimeSpan.Zero;
            }

            if (pressed && screen.ScreenManager.Game.InputManager.LeftButtonReleased && rectangle.Contains(screen.ScreenManager.Game.InputManager.WorldPosition.X, screen.ScreenManager.Game.InputManager.WorldPosition.Y))
            {
                OnSelect();
                pressed = false;
                animationState = ButtonAnimationState.Releasing;
                scaleTimeElapsed = TimeSpan.Zero;
            }
        }
Example #5
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;
        }