Ejemplo n.º 1
0
        public void Update(GameTime gameTime)
        {
            //TouchCollection touchCollection = TouchPanel.GetState();
            //if (touchCollection.Count > 0)
            //{
            //    Rectangle bound = new Rectangle((int)position.X, (int)position.Y, (int)size.X, (int)size.Y);
            //    int mouseX = (int)Resolution.AdjustWidthWithScren(touchCollection[0].Position.X);
            //    int mouseY = (int)Resolution.AdjustWidthWithScren(touchCollection[0].Position.Y);
            //    if (bound.Contains(mouseX, mouseY))
            //    {
            //        onClick();
            //    }
            //}
            var mouseState = Mouse.GetState();

            if (mouseState.LeftButton == ButtonState.Pressed)
            {
                Rectangle bound  = new Rectangle((int)position.X, (int)position.Y, (int)size.X, (int)size.Y);
                int       mouseX = (int)Resolution.AdjustWidthWithScren(mouseState.Position.X);
                int       mouseY = (int)Resolution.AdjustWidthWithScren(mouseState.Position.Y);
                if (bound.Contains(mouseX, mouseY))
                {
                    onClickEvent();
                }
            }
        }
Ejemplo n.º 2
0
        public override void Update(GameTime gameTime)
        {
            #region Keyboard
            KeyboardState        = Keyboard.GetState();
            Pipe.player.commands = EnumMoveCommand.None;
            if (KeyboardState.IsKeyDown(Keys.Q))
            {
                Pipe.player.commands = Pipe.player.commands | EnumMoveCommand.Left;
            }
            if (KeyboardState.IsKeyDown(Keys.D))
            {
                Pipe.player.commands = Pipe.player.commands | EnumMoveCommand.Right;
            }
            if (KeyboardState.IsKeyDown(Keys.Z))
            {
                Pipe.player.commands = Pipe.player.commands | EnumMoveCommand.Up;
            }
            if (KeyboardState.IsKeyDown(Keys.S))
            {
                Pipe.player.commands = Pipe.player.commands | EnumMoveCommand.Bottom;
            }
            #endregion

            #region Mouse
            _mouseState        = Mouse.GetState();
            Pipe.MousePosition = new Vector2(Resolution.AdjustWidthWithScren(_mouseState.Position.X), Resolution.AdjustWidthWithScren(_mouseState.Position.Y));
            if (_mouseState.LeftButton == ButtonState.Pressed)
            {
                Pipe.MouseClick      = new Vector2(Resolution.AdjustWidthWithScren(_mouseState.Position.X), Resolution.AdjustWidthWithScren(_mouseState.Position.Y));
                Pipe.player.commands = Pipe.player.commands | EnumMoveCommand.LeftClick;
            }
            if (_mouseState.RightButton == ButtonState.Pressed)
            {
                Pipe.MouseClick      = new Vector2(Resolution.AdjustWidthWithScren(_mouseState.Position.X), Resolution.AdjustWidthWithScren(_mouseState.Position.Y));
                Pipe.player.commands = Pipe.player.commands | EnumMoveCommand.RightClick;
            }
            #endregion

            #region update
            test.Update(gameTime);
            #endregion
        }