Я пытаюсь загрузить текстуру в MonoGame с помощью Xamarin Studio. Мой код устанавливается, как показано ниже:ContentLoadException в MonoGame
#region Using Statements
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Storage;
using Microsoft.Xna.Framework.Input;
#endregion
namespace TestGame
{
/// <summary>
/// This is the main type for your game
/// </summary>
public class Game1 : Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
//Game World
Texture2D texture;
Vector2 position = new Vector2(0,0);
public Game1()
{
graphics = new GraphicsDeviceManager (this);
Content.RootDirectory = "Content";
graphics.IsFullScreen = false;
}
/// <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);
//Content
texture = Content.Load<Texture2D>("player");
}
/// <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)
{
// For Mobile devices, this logic will close the Game when the Back button is pressed
if (GamePad.GetState (PlayerIndex.One).Buttons.Back == ButtonState.Pressed) {
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)
{
graphics.GraphicsDevice.Clear (Color.CornflowerBlue);
//Draw
spriteBatch.Begin();
spriteBatch.Draw (texture, position, Color.White);
spriteBatch.End();
base.Draw (gameTime);
}
}
}
Когда я его отладки он дает мне ошибку:
Microsoft.Xna.Framework.Content.ContentLoadException: Не удалось загрузить игрок актив как не -content file! ---> Microsoft.Xna.Framework.Content.ContentLoadException: Каталог не найден. ---> System.IO.DirectoryNotFoundException: Не удалось найти часть пути 'C: \ Users \ Flame \ Documents \ Projects \ TestGame \ TestGame \ bin \ Debug \ Content \ player.xnb'. ---> System.Exception:
--- Конец внутренней трассировки стека исключений ---
по меньшей System.IO .__ Error.WinIOError (Int32, String ERRORCODE maybeFullPath)
на на System.IO.FileStream.Init (строка пути, режим FileMode, доступа FileAccess, права Int32, Boolean useRights, Обменник акций, Int32 BufferSize, варианты FileOptions, SECURITY_ATTRIBUTES secAttrs, Строка msgPath, Boolean bFromProxy, Boolean useLongPath)
на на System.IO.FileStream..ctor (строка пути, режим FileMode, доступ FileAccess, Обменник акцию, Int32 BufferSize, FileOptions опции, строка msgPath, Boolean bFromProxy)
на в System.IO.FileStream ..ctor (String путь, режим FileMode, FileAccess доступа, Обменник доля)
в в System.IO.File.OpenRead (String путь)
в в Microsoft.Xna.Framework.TitleContainer.OpenStream (Строковое наименование)
в в Microsoft.Xna.Framework.Content.ContentManager.OpenStream (String assetName)
--- Конец внутренней трассировки стека исключений ---
в в Microsoft.Xna.Framework.Content .ContentManager.OpenStream (String assetName)
по меньшей Microsoft.Xna.Framework.Content.ContentManager.ReadAsset [T] (String assetName, Action`1 recordDisposableObject)
--- Конец внутренней трассировки стека исключений ---
по крайней Microsoft.Xna.Framework.Content.ContentManager.ReadAsset [T] (String assetName, Action`1 recordDisposableObject)
по крайней Microsoft.Xna.Framework.Content.ContentManager.Load [Т] (Строка assetName)
на TestGame.Game1.LoadContent() в C: \ Users \ Пламя \ Documents \ Проекты \ \ TestGame TestGame \ Game1.CS: 0
в в Microsoft.Xna.Framework.Game.Initialize()
на TestGame.Game1.Initialize() в C: \ Users \ Пламя \ Documents \ Projects \ TestGame \ TestGame \ Game1 .cs: 0
в в Microsoft.Xna.Framework.Game.DoInitialize()
по меньшей Microsoft.Xna.Framework.Game.Run (GameRunBehavior runBehavior)
в в Microsoft.Xna. Framework.Game.Run()
в TestGame.Program.Main() в C: \ Users \ Flame \ Documents \ Projects \ TestGame \ TestGame \ Program.cs: 0
Так что я делаю неправильно?
Есть ли player.xnb в папке Content под bin/Debug? – borrillis
Нет, нет. – FlameDra
На какой платформе вы строите? iOS или Android? По крайней мере, для iOS мне пришлось создать проект контента Monogame и использовать обработчик содержимого текстуры Monogame, чтобы полученные xnb-файлы были совместимы с iOS, который использует свой собственный формат текстуры. Кроме того, как упоминалось в ответе Ричарда, вам нужно будет установить «Построить действия» на «Контент» и «Копировать в выходной каталог» на «Копировать, если новый» – RobCurr