在c#控制台上加载内容文件夹

本文关键字:文件夹 加载 控制台 | 更新日期: 2023-09-27 17:50:30

我是新来的,我的项目遇到了问题。
我的项目是一个c#主机游戏,混合了xna游戏。我的问题与我的项目,是我添加了一个内容文件夹到它加载xna精灵等,但每次我让它运行,它显示,文件没有找到纹理加载。我想看看问题是不是出在路径上,但不是。在我看来,它似乎不认识contents文件夹,或者换句话说,它威胁着它不存在。
我试着在谷歌上搜索,但它总是给我奇怪的结果,
我在这个网站上寻找解决方案,没有一个是我不想要的。
我如何让它识别我的内容文件夹,以便能够加载精灵和其他东西?

public class Game : Microsoft.Xna.Framework.Game
{
    public GraphicsDeviceManager graphics;
    public SpriteBatch spriteBatch;
    public Game()
    {
        graphics = new GraphicsDeviceManager(this);
        graphics.PreferredBackBufferWidth = 640;
        graphics.PreferredBackBufferHeight = 480;
        graphics.IsFullScreen = false;
        Content.RootDirectory = "Content"; 
    }
    protected override void Initialize()
    {
        base.Initialize();
    }
    protected override void LoadContent()
    {
        spriteBatch = new SpriteBatch(GraphicsDevice);
        Program.TestPlayer = Content.Load<Texture2D>("characters/blue"); //Here is where gives the error
        Program.Tiles = Content.Load<Texture2D>("tiles"); //this gives error if the above script is commented.
    }
    protected override void UnloadContent()
    {
    }
    protected override void Update(GameTime gameTime)
    {
        switch (Procedures.gmode)
        {
            case GameMode.ExplorationMode:
                Exploration.ExplorationMode();
                break;
            default:
                this.EndRun();
                return;
        }
        base.Update(gameTime);
    }
    protected override void Draw(GameTime gameTime)
    {
        GraphicsDevice.Clear(Color.White);
        spriteBatch.Begin();
        switch (Procedures.gmode)
        {
            case GameMode.ExplorationMode:
                Exploration.DrawMap();
                Procedures.player.DrawTamer(spriteBatch);
                break;
        }
        spriteBatch.End();
        base.Draw(gameTime);
    }
}

在c#控制台上加载内容文件夹

我必须做一些不同的事情来解决这个问题,除了…不推荐,而且有点烦人。
我必须在xna上创建另一个项目,并使其将内容文件传递到xna文件,然后将内容文件夹移动到我的项目文件夹。
除了让人讨厌之外,它至少是有效的。

听起来好像是有些设置不对。

确保Content项目在主项目的"Content References"中被引用。

还要确保Content项目中的"Content根目录"设置为"Content"(或者与你的"Content"相同)。RootDirectory = 'Content';"被设置为).

和"我的问题与我的项目,是我添加了一个内容文件夹"这听起来像你添加了一个正常的文件夹到xna项目,但你需要使用一个内容项目,这样你的资源将被编译和引用。


编辑

根据你的图像,似乎你没有一个xna游戏项目,但一个正常项目。试图让一个 xna项目和地点而不是你的游戏文件,然后引用内容项目 xna游戏项目(在xna游戏项目您将自动获得一个新的内容项目隔层具有一定的xna游戏项目,所以你可以使用,而不是你的,所以你不必惹设置,只是把你的文件)。