0
是否可以在XNA遊戲中打開自定義屏幕或彈出窗口(模式)。該想法是向用戶顯示一些選項wrt遊戲和其他應用程序將成爲應用程序套件的一部分。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。
Krz。
感謝Blau.I試過DrawableGameComponent解決方案(從文章中複製的代碼),但在vain.No無論我做什麼,僅僅顯示一個空白屏幕。
在遊戲中構造我把情況和調用方法
if (showScreen)
{
LaunchScreen launcher = new LaunchScreen(this, null);
//Components.Add(launcher);
launcher.Show();
}
else{///constructor code}
我也提出一個條件在遊戲初始化,這樣如果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之前打開的窗口完全糊塗了實際的遊戲運行/初始化。 KRZ
我在尋找加載DrawableGameComponent或者用於創建UI屏幕的東西。另外,我正在使用VS 2010 Express for Windows Phone;是否可以包含Windows窗體模板。 – srcKode
我已經添加了一個DrawableGameComponent的源代碼,該代碼應該做你想做的事......你只需要啓用/禁用它來顯示/隱藏表單。 – Blau
我認爲在啓動遊戲之前彈出一個窗口意味着一個新的窗口窗體......我想你只需要一個屏幕管理器系統......你想讓你的屏幕或彈出窗口成爲你遊戲的一部分嗎? – Blau