【发布时间】:2016-01-26 05:18:56
【问题描述】:
最近我在将资源加载为 Texture2D 时遇到了一些麻烦。我尝试将路径更改为“..\assetName”、“assetName”、“assetName.png”和“..\assetName.png”(正如this问题的答案之一所建议的那样,但他们都没有作业。我还尝试在添加文件时使用 MonoGame 内容管道,并且“复制到输出目录”参数当前设置为“始终复制”。
我尝试使用一些非常简单的代码创建一个新项目来加载内容文件,它的内容如下
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
namespace TempSol2
{
/// <summary>
/// This is the main type for your game.
/// </summary>
public class Game1 : Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
Texture2D texture;
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
texture = Content.Load<Texture2D>("Character1");
}
但我每次都会遇到同样的错误。
异常消息显示为标题显示“无法将 Character1 资产加载为非内容文件”,内部异常显示“未找到内容文件”。
我还检查了文件应该复制到的文件夹,它包含 .png 和 .xnb
【问题讨论】:
标签: c# exception assets monogame