1

なぜ機能しないのかわかりません。ありがとうございます。大量のコードで申し訳ありませんが、エラーがどこにあるのかわかりません。問題は、黒い画面とロード マウスだけが表示されることです。ロード画面やメニューは表示されません。

public class Game1 : Microsoft.Xna.Framework.Game
{
    GraphicsDeviceManager graphics;
    SpriteBatch spriteBatch;
    SpriteBatch mBatch;
    Texture2D mTheQuantumBros2;
    MenuComponent menuComponent;
    public static Rectangle screen;
    public static string GameState = "Menu";
    public Game1()
    {
        graphics = new GraphicsDeviceManager(this);
        Content.RootDirectory = "Content";
        graphics.PreferMultiSampling = false;
        graphics.IsFullScreen = true;
        graphics.PreferredBackBufferWidth = 1366;
        graphics.PreferredBackBufferHeight = 768;
        graphics.ApplyChanges();
    }

    protected override void Initialize()
    {
        // TODO: Add your initialization logic here

        base.Initialize();
    }

    protected override void LoadContent()
    {
        spriteBatch = new SpriteBatch(GraphicsDevice);
        mBatch = new SpriteBatch(this.graphics.GraphicsDevice);
        ContentManager aLoader = new ContentManager(this.Services);
        aLoader.RootDirectory = "Content";
        mTheQuantumBros2 = aLoader.Load<Texture2D>("TheQuantumBros2") as Texture2D;
        menuComponent.LoadContent(Content);
    }

    protected override void UnloadContent()
    {

    }

    /// <param name="gameTime">Provides a snapshot of timing values.</param>
    protected override void Update(GameTime gameTime)
    {
        if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            this.Exit();
        switch (GameState)
        {
            case "Menu":
                menuComponent.Update(gameTime);
            break;
        }

        base.Update(gameTime);
    }

    /// <param name="gameTime">Provides a snapshot of timing values.</param>
    protected override void Draw(GameTime gameTime)
    {
        GraphicsDevice.Clear(Color.Black);

        spriteBatch.Begin();
        switch (GameState)
        {
            case "Menu":
                menuComponent.Draw(spriteBatch);
                break;
        }
        base.Draw(gameTime);
    }
}

}

他のクラス:

class MenuComponent
{
    KeyboardState keyboard;
    KeyboardState prevKeyboard;

    SpriteBatch mBatch;
    Texture2D mTheQuantumBros2;

    GameTime gameTime;

    MouseState mouse;
    MouseState prevMouse;

    SpriteFont spriteFont;

    List<string> buttonList = new List<string>();

    int selected = 0;

    public MenuComponent()
    {
        buttonList.Add("Campaign");
        buttonList.Add("Multiplayer");
        buttonList.Add("Zombies");
        buttonList.Add("Quit Game");

    }

    public void LoadContent(ContentManager Content)
    {
        spriteFont = Content.Load<SpriteFont>("Font");
    }

    public void Update(GameTime gameTime)
    {
        keyboard = Keyboard.GetState();
        mouse = Mouse.GetState();

        if (CheckKeyboard(Keys.Up))
        {
            if (selected > 0) selected--;
        }

        if (CheckKeyboard(Keys.Down))
        {
            if (selected < buttonList.Count - 1) selected++;
        }

        prevMouse = mouse;
        prevKeyboard = keyboard;
    }

    public bool CheckMouse()
    {
        return (mouse.LeftButton == ButtonState.Pressed && prevMouse.LeftButton == ButtonState.Released);
    }

    public bool CheckKeyboard(Keys key)
    {
        return (keyboard.IsKeyDown(key) && prevKeyboard.IsKeyDown(key));
    }

    public void Draw(SpriteBatch spriteBatch)
    {
        Color color;
        int linePadding = 3;

        spriteBatch.Begin();
        mBatch.Begin();
        mBatch.Draw(mTheQuantumBros2, new Rectangle(300, 150, mTheQuantumBros2.Width, mTheQuantumBros2.Height), Color.White);
        if (gameTime.TotalGameTime.TotalSeconds <= 3)
        {
            mBatch.End();
            for (int i = 0; i < buttonList.Count; i++)
            {
                color = (i == selected) ? Color.LawnGreen : Color.Gold;
                spriteBatch.DrawString(spriteFont, buttonList[i], new Vector2((Game1.screen.Width / 2) - (spriteFont.MeasureString(buttonList[i]).X / 2), (Game1.screen.Height / 2) - (spriteFont.LineSpacing * (buttonList.Count) / 2) + ((spriteFont.LineSpacing + linePadding) * i)), color);
            }
            spriteBatch.End();
        }
    }
}

}

4

2 に答える 2