未找到资产XNA [英] Asset not found XNA

查看:224
本文介绍了未找到资产XNA的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很新的XNA,我开始按照在屏幕上绘制图像的教程。
我能到我的图像移动到文件夹的内容,但当我尝试在我的code使用它,它不能被发现。

I am very new to XNA and I began by following a tutorial that draws an image on the screen. I was able to move my image into the Content folder but when I try to use it in my code, it can't be found.

我使用的是资产的名字,我只是找不到什么,我做错了。
本教程采用XNA 3.0和我使用Visual Studio 2010,不知道的事项或没有。

I am using the asset name and I just cannot find what I am doing wrong. The tutorials use XNA 3.0 and I am using Visual Studio 2010, not sure if that matters or not.

下面是我的code

public class Game1 : Microsoft.Xna.Framework.Game
{
    Vector2 mPosition = new Vector2(0, 0);
    Texture2D mSpriteTexture;

    GraphicsDeviceManager graphics;
    SpriteBatch spriteBatch;

    public Game1()
    {
        graphics = new GraphicsDeviceManager(this);
        Content.RootDirectory = "Content";
    }


    protected override void Initialize()
    {
        base.Initialize();
    }

    protected override void LoadContent()
    {
        spriteBatch = new SpriteBatch(GraphicsDevice);

        mSpriteTexture = Content.Load<Texture2D>("Face");
    }


    protected override void UnloadContent()
    {
    }

    protected override void Update(GameTime gameTime)
    {

        if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            this.Exit();


        base.Update(gameTime);
    }

    protected override void Draw(GameTime gameTime)
    {
        GraphicsDevice.Clear(Color.Black);

        spriteBatch.Begin();
        spriteBatch.Draw(mSpriteTexture, mPosition, Color.White);
        spriteBatch.End();

        base.Draw(gameTime);
    }
}

}

错误写着ContentLoadException了未处理,未找到文件。

The error reads "ContentLoadException was Unhandled. File not found.

Solution Explorer中

我希望这是足够的信息。也是我的文件的资产名称是脸部。

I hope this is enough information. Also the asset name of my file is Face.

先谢谢了。

推荐答案

如果您添加您的文件内容项目(这些是新的4.0)其他需要检查的事项是确保该文件是一个对于一个Texture2D支持的格式(为.jpg,.png .BMP,.TGA)。在此之后,点击图像,并验证该资产的名字是正确的和匹配您使用的是code,准确的套管/拼写用这个名字来加载它。如果这是正确的话还请确保图像内容供应商是否设置正确是一个Texture2D。然后验证另一件事是,确保你的图像是在内容项目的根文件夹不在家。如果一个文件夹中有它,那么你需要加载时,它包含的文件夹名称(或名称)。

If you've added your file to the Content project (those are new for 4.0) the other things to check would be to make sure the file is one of the supported formats for a Texture2D (.jpg, .png, .bmp, .tga). After that, click on the image and verify that the asset name is correct and matching the exact casing/spelling that you're using in code to load it by that name. If that's correct then also make sure that the Content Importer for the image is set correctly to be a Texture2D. And then another thing to verify would be to make sure you're image is in the root of the Content project and not in a folder. If you have it in a folder, then you need to include the folder name (or names) when loading it.

如果您确认所有的,那么你可能需要张贴图片或样品的项目,使我们可以看一看,看看我们是否发现任何方式。

If you've verified all that then you may need to post an image or a sample project so that we can take a look and see if we spot anything that way.

从该截图它看起来像你需要在测试项目右键单击并说添加内容参考。然后,您需要选择你的测试(内容)项目作为参考。这应该在默认情况下已经发生了,当你创造了这个新的游戏项目,我不知道为什么它看起来像它已被删除。

From that screenshot it looks like you need to right-click on the "Test" project and say "Add Content Reference". You'll then need to pick your "Test (Content)" project as that reference. That should have happened by default when you created this new game project and I'm not sure why it looks like it was removed.

这篇关于未找到资产XNA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆