I'm trying to make my game load compiled xnb textures outside the main game class, as I usually do with my image files (which are not compiled to xnb format) and it doesn't work.
Texture2D.FromStream
returns "unexpected error", and
using (var g = new Game1())
{
Texture2D t2d = g.Content.Load<Texture2D>(file);
}
says that the file doesn't exist, while File.Exists
right next to it shows that it indeed exists.
I can't add those xnb files to my project, because I won't have them at compile time. How do I solve this?
More code:
public void LoadXNA(Microsoft.Xna.Framework.Content.ContentManager cmgr, string path)
{
string xnaTexturesPath = path.Substring(0, path.LastIndexOf("\\")) + "\\textures xna";
if (Directory.Exists(xnaTexturesPath))
{
var files = Directory.GetFiles(xnaTexturesPath, "*.xnb");
foreach(var file in files)
{
string filename = Path.GetFileNameWithoutExtension(file);
string ext = Path.GetExtension(file);
string pathNoext = file.Replace(ext, "");
var t2d = cmgr.Load < Texture2D > (pathNoext);
}
}
}