Я следовал руководству по созданию главного меню, но оно не показывает мне, как я могу нажимать кнопки и переходить на другой экран и т. Д. c. То, на чем я пытаюсь в основном сосредоточиться, - это возможность щелкнуть имеющуюся у меня кнопку Параметры, которая затем, вероятно, будет иметь сцену с титрами для игры, которая создается в моей группе.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using menuRMA.Controls;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
namespace menuRMA.States
{
public class menuState : State
{
private List<Component> _components;
public menuState(Game1 game, GraphicsDevice graphicsDevice, ContentManager content) : base(game,
graphicsDevice, content)
{
var buttonTexture = _content.Load<Texture2D>("Controls/Button");
var buttonFont = _content.Load<SpriteFont>("Fonts/Font");
var titleGameButton = new Button(buttonTexture, buttonFont)
{
Position = new Vector2(300, 150),
Text = "Respect My Authority",
};
titleGameButton.Click += TitleGameButton_Click;
var playGameButton = new Button(buttonTexture, buttonFont)
{
Position = new Vector2(300, 200),
Text = "Play",
};
playGameButton.Click += PlayGameButton_Click;
var optionsGameButton = new Button(buttonTexture, buttonFont)
{
Position = new Vector2(300, 250),
Text = "Options",
};
optionsGameButton.Click += OptionsGameButton_Click;
var exitGameButton = new Button(buttonTexture, buttonFont)
{
Position = new Vector2(300, 300),
Text = "Exit",
};
exitGameButton.Click += ExitGameButton_Click;
_components = new List<Component>()
{
titleGameButton,
playGameButton,
optionsGameButton,
exitGameButton,
};
}
private void TitleGameButton_Click(object sender, EventArgs e)
{
}
public override void Draw(GameTime gameTime, SpriteBatch spriteBatch)
{
spriteBatch.Begin();
foreach (var component in _components)
component.Draw(gameTime, spriteBatch);
spriteBatch.End();
}
private void OptionsGameButton_Click(object sender, EventArgs e)
{
Console.WriteLine("Options");
}
private void PlayGameButton_Click(object sender, EventArgs e)
{
_game.ChangeState(new gameState(_game, _graphicsDevice, _content));
}
public override void PostUpdate(GameTime gameTime)
{
// remove sprites if they're not needed
}
public override void Update(GameTime gameTime)
{
foreach (var component in _components)
component.Update(gameTime);
}
private void ExitGameButton_Click(object sender, EventArgs e)
{
_game.Exit();
}
}
}