public static void Update() { if (GKeyboard.IsKeyPressed(Keys.Enter)) { _show = false; } }
public override void Update(GameTime gameTime) { _mousePosition = GMouse.GetState().Position; _itemSelected = false; for (var i = 0; i < _items.Count; i++) { if (_items[i].Rect.Contains(_mousePosition)) { SelectedItemIndex = i; _itemSelected = true; } } if (GKeyboard.IsKeyPressed(Keys.Up)) { SelectedItemIndex -= 1; } if (GKeyboard.IsKeyPressed(Keys.Down)) { SelectedItemIndex += 1; } if (SelectedItem.Action != null && SelectedItem.Type == ActionType.Update && (GKeyboard.IsKeyPressed(Keys.Enter) || (Mouse.GetState().LeftButton == ButtonState.Pressed && _itemSelected))) { Invoke(); } }
protected override void Update(GameTime gameTime) { try { GKeyboard.UpdateState(); GMouse.UpdateState(); if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || GKeyboard.IsKeyDown(Keys.Escape)) { Exit(); } if (GKeyboard.IsKeyPressed(Keys.A)) { if (GMouse.AlkashCursor) { GMouse.AlkashCursor = false; } else { GMouse.AlkashCursor = true; } } SceneManager.ActiveScene.Update(gameTime); foreach (var ctrl in Controls) { ctrl.Update(gameTime); } base.Update(gameTime); } catch (Exception ex) { Console.WriteLine($"Update method exception:\n{ex.Message}"); } }
public override void Draw(GameTime gameTime) { var position = new Vector2(_items.First().Rect.X + _items.First().Rect.Width / 2, _items.First().Rect.Y + _items.First().Rect.Height / 6); Game.SpriteBatch.Begin(); //_spriteBatch.DrawString(_font, _items[0].Text, center - _font.MeasureString(_items[0].Text) / 2, Color.Red); if (SelectedItemIndex != -1) { var item = _items[SelectedItemIndex]; Game.SpriteBatch.Draw(_selectedItemRect, item.Rect, _selectedItemRectColor); } foreach (var item in _items) { if (_menuTextAlign == Align.Center) { Game.SpriteBatch.DrawString(ItemsFont, item.Text, new Vector2(position.X - ItemsFont.MeasureString(item.Text).X / 2, position.Y), Color.Black); } if (_menuTextAlign == Align.Left) { Game.SpriteBatch.DrawString(ItemsFont, item.Text, new Vector2(position.X - _maxItemWidth / 2, position.Y), Color.Black); } if (_menuTextAlign == Align.Right) { Game.SpriteBatch.DrawString(ItemsFont, item.Text, new Vector2(position.X + _maxItemWidth / 2 - ItemsFont.MeasureString(item.Text).X, position.Y), Color.Black); } position.Y += _itemHeight; } Game.SpriteBatch.End(); if (SelectedItem.Action != null && SelectedItem.Type == ActionType.Draw && (GKeyboard.IsKeyPressed(Keys.Enter) || (Mouse.GetState().LeftButton == ButtonState.Pressed && _itemSelected))) { Invoke(); } }