Можно ли открыть пользовательский экран или всплывающее окно (модальное) в игре XNA. Идея состоит в том, чтобы показать пользователю несколько вариантов игры и других приложений, которые станут частью набора приложений.
public class MyGame : Game
{
#region Initialization
/// <summary>
/// Creates a new instance of the game.
/// </summary>
public MyGame()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
///etc;
}
/// <summary>
/// Performs initializations required by the game.
/// </summary>
protected override void Initialize()
{
///I would Like to open a new screen before the actual game
/// menu is displayed ... also return to this screen after the logic is run
/// in that screen
base.Initialize();
}
}
Любые идеи / предложения / образцы.
Спасибо в Adv.
КРЗ.
Спасибо, Blau. Я попробовал решение DrawableGameComponent (скопировал код из статьи), но тщетно. Независимо от того, что я делаю, отображается только пустой экран.
В конструкторе игр я ставлю условие и вызываю метод как
if (showScreen)
{
LaunchScreen launcher = new LaunchScreen(this, null);
//Components.Add(launcher);
launcher.Show();
}
else{///constructor code}
Я также поместил условие в Game Initialize, чтобы, если showScreen был flase, то выполнялся. (Не уверен, что это правильный способ сделать)
Класс выглядит так:
public class LaunchScreen : DrawableGameComponent
{
private Texture2D backgroundImage = null;
private SpriteBatch spriteBatch = null;
public LaunchScreen(Game game, Texture2D texture)
: base(game)
{
backgroundImage = texture;
Visible = false;
Enabled = false;
}
public virtual void Show()
{
Visible = true;
Enabled = true;
}
public virtual void Hide()
{
Visible = false;
Enabled = false;
}
public override void Initialize()
{
base.Initialize();
}
public override void Update(GameTime gameTime)
{
base.Update(gameTime);
}
public override void Draw(GameTime gameTime)
{
//if (backgroundImage != null)
//{
spriteBatch = new SpriteBatch(base.GraphicsDevice);
if (Game.Services.GetService(typeof(SpriteBatch)) == null)
Game.Services.AddService(typeof(SpriteBatch), spriteBatch);
Rectangle screen = new Rectangle(0, 0,
Game.Window.ClientBounds.Width,
Game.Window.ClientBounds.Height);
Texture2D lauT2D = this.Game.Content.Load<Texture2D>("Textures/BG");
spriteBatch.Draw(lauT2D, screen, Color.White);
//}
///SpriteFont font = this.Game.Content.Load<SpriteFont>("Fonts/MenuFont");
///Vector2 spritePosition = Vector2.One;
///spriteBatch.DrawString(font, "Goodness ME", spritePosition, Color.White);
base.Draw(gameTime);
}
}
Я полностью запутался в том, как инициализировать GraphicDevice и SpriteBatch и открыть окно перед тем, как будет запущена / инициализирована настоящая игра.
КРЗ