File XNA文件夹层次结构

File XNA文件夹层次结构,file,xna,File,Xna,好的,我是新来XNA的,我只是想在屏幕上显示一幅图像。我相信我已经将图像添加到VS2010程序的内容文件夹中,但是当我尝试运行该程序时,会出现一个错误,显示“未找到文件”。所以我想知道将图像放在哪个文件夹中才能调用图像文件Tank.png。 代码很简单: namespace Aceldama_Windows_Game { /// <summary> /// This is the main type for your game /// </summary> public

好的,我是新来XNA的,我只是想在屏幕上显示一幅图像。我相信我已经将图像添加到VS2010程序的内容文件夹中,但是当我尝试运行该程序时,会出现一个错误,显示“未找到文件”。所以我想知道将图像放在哪个文件夹中才能调用图像文件Tank.png。 代码很简单:

namespace Aceldama_Windows_Game
{
/// <summary>
/// This is the main type for your game
/// </summary>
public class Game1 : Microsoft.Xna.Framework.Game
{
    GraphicsDeviceManager graphics;
    SpriteBatch spriteBatch;
    Vector2 mPosition = new Vector2(0, 0);
    Texture2D mSpriteTexture;
    public Game1()
    {
        graphics = new GraphicsDeviceManager(this);
        Content.RootDirectory = "Content";

    }

    /// <summary>
    /// Allows the game to perform any initialization it needs to before starting to run.
    /// This is where it can query for any required services and load any non-graphic
    /// related content.  Calling base.Initialize will enumerate through any components
    /// and initialize them as well.
    /// </summary>
    protected override void Initialize()
    {
        // TODO: Add your initialization logic here

        base.Initialize();
    }

    /// <summary>
    /// LoadContent will be called once per game and is the place to load
    /// all of your content.
    /// </summary>
    protected override void LoadContent()
    {
        // Create a new SpriteBatch, which can be used to draw textures.
        spriteBatch = new SpriteBatch(GraphicsDevice);

        // TODO: use this.Content to load your game content here
        mSpriteTexture = this.Content.Load<Texture2D>("Tank");
    }

    /// <summary>
    /// UnloadContent will be called once per game and is the place to unload
    /// all content.
    /// </summary>
    protected override void UnloadContent()
    {
        // TODO: Unload any non ContentManager content here
    }

    /// <summary>
    /// Allows the game to run logic such as updating the world,
    /// checking for collisions, gathering input, and playing audio.
    /// </summary>
    /// <param name="gameTime">Provides a snapshot of timing values.</param>
    protected override void Update(GameTime gameTime)
    {
        // Allows the game to exit
        if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            this.Exit();

        // TODO: Add your update logic here

        base.Update(gameTime);
    }

    /// <summary>
    /// This is called when the game should draw itself.
    /// </summary>
    /// <param name="gameTime">Provides a snapshot of timing values.</param>
    protected override void Draw(GameTime gameTime)
    {
        GraphicsDevice.Clear(Color.CornflowerBlue);

        // TODO: Add your drawing code here
        spriteBatch.Begin();
        spriteBatch.Draw(mSpriteTexture, mPosition, Color.White);
        spriteBatch.End();

        base.Draw(gameTime);
    }
}
namespace Aceldama\u Windows\u游戏
{
/// 
///这是游戏的主要类型
/// 
公共类游戏1:Microsoft.Xna.Framework.Game
{
图形管理器图形;
SpriteBatch SpriteBatch;
Vector2位置=新的Vector2(0,0);
纹理2维纹理;
公共游戏1()
{
graphics=新的GraphicsDeviceManager(此);
Content.RootDirectory=“Content”;
}
/// 
///允许游戏在开始运行之前执行任何需要的初始化。
///在这里,它可以查询任何必需的服务,并加载任何非图形化的服务
///相关内容。调用base.Initialize将枚举所有组件
///并对它们进行初始化。
/// 
受保护的覆盖无效初始化()
{
//TODO:在此处添加初始化逻辑
base.Initialize();
}
/// 
///LoadContent将在每个游戏中调用一次,并且是加载的地方
///你所有的内容。
/// 
受保护的覆盖void LoadContent()
{
//创建一个新的SpriteBatch,可用于绘制纹理。
spriteBatch=新spriteBatch(图形设备);
//TODO:使用此.Content在此处加载游戏内容
mSpriteTexture=此.Content.Load(“储罐”);
}
/// 
///UnloadContent将在每个游戏中调用一次,并且是卸载的地方
///所有内容。
/// 
受保护的覆盖无效UnloadContent()
{
//TODO:在此卸载任何非ContentManager内容
}
/// 
///允许游戏运行逻辑,例如更新世界,
///检查碰撞、收集输入和播放音频。
/// 
///提供计时值的快照。
受保护覆盖无效更新(游戏时间游戏时间)
{
//允许游戏退出
if(GamePad.GetState(PlayerIndex.One).Buttons.Back==ButtonState.Pressed)
这是Exit();
//TODO:在此处添加更新逻辑
更新(游戏时间);
}
/// 
///这就是所谓的比赛应该平局的时候。
/// 
///提供计时值的快照。
受保护覆盖无效绘制(游戏时间游戏时间)
{
图形设备。清晰(颜色:矢车菊蓝);
//TODO:在此处添加图形代码
spriteBatch.Begin();
spriteBatch.Draw(mSpriteTexture,Composition,Color.White);
spriteBatch.End();
基础。抽签(游戏时间);
}
}
}


我应该将图像放在哪个文件夹中才能直接调用文件,而无需放置完整的文件路径?本质上,问题在于,似乎无论我将tank.png文件放在何处(无论是在包含可执行文件的文件中还是在内容文件夹中)

XNA内容管道都会将内容项目引用的项目转换为XNB文件。
ContentManager
然后加载这些XNB文件

因此,首先要检查的是XNB文件是否在输出目录中预期的位置创建

根据您发布的代码,使用
Content.RootDirectory=“Content”
Content.Load(“Tank”)
,假设使用Windows调试版本,它将查找以下文件:

 bin/x86/Debug/Content/Tank.xnb

如果您更改了内容项目输出目录,则还需要更改在代码中设置的
RootDirectory

因此,在无休止地搜索web之后,我发现了问题所在;p如果代码没有问题,问题是我需要在项目中创建对内容文件夹的引用。上传了解决方案资源管理器的图片,以显示我需要做什么!


在内容参考下,我没有添加“Aceldama_windows_gameContent”。需要在那里引用游戏内容文件夹中的图像

尝试将其更改为:
mSpriteTexture=this.Content.Load(“坦克”)我也做了同样的事情。错误是找不到文件,所以我检查了它们是否被创建为.xnb文件,而不是。.xnb文件是在您将其导入项目本身时创建的吗?它们是作为构建过程的一部分创建的。有关如何添加内容以便正确构建内容的说明,请阅读。和一个完整的概述。