Hello! I want to use xnb files from game that was developed with monogame for modding. But when I try to load them in my project (tex = Content.Load(“texturename”)
I see error: An unhandled exception of type ‘Microsoft.Xna.Framework.Content.ContentLoadException’ occurred in MonoGame.Framework.dll
Additional information: Could not load walls asset as a non-content file!
Please help me to load this files.
If it’s a texture u should be doining
Content.Load<>(" path"):
Can you please give me example code? I am beginner. I am use this:
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
namespace Game2
{
///
/// This is the main type for your game.
///
public class Game1 : Game
{
GraphicsDeviceManager _graphics;
SpriteBatch _spriteBatch;
Texture2D tex;
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
tex = Content.Load<Texture2D>("walls");
}
/// <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)
{
// 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(tex, Vector2.Zero, Color.White);
_spriteBatch.End();
base.Draw(gameTime);
}
}
}
It works fine with terraria xnb files and load them.
Ok
What platform is it for?
Is the c b a texture file?
Does the file exist it you project and is it in the content directory?
Originally this xnb files from game for Android. But I use monogame windows project in visual studio. should I use only android project if I want load this files? Its texture file, yes. This file https://mega.co.nz/#!yMtSlDAT!0AfDhAL8SQ06Pct0GH8f2Nv2GMeEffYo0sROX9H1ZKA (name of this file is right in my content directory - walls.xnb)
Yes, I put it in content directory.
Every platform other than Windows is case-sensitive. so make sure the filename and path are all absolutely correct. On Android, add the xnb file to a Content folder in your project and set the Build Action to AndroidAsset.