Я пытаюсь загрузить изображение в MonoGame (без Content.Load), но когда я пытаюсь запустить проект, я сталкиваюсь с System.IO.FileNotFoundException и надеялся, что кто-нибудь подскажет что я делаю неправильно.
Сообщение об ошибке: System.IO.FileNotFoundException: 'Не удалось найти файл 'G:\Min enhet\C#\FirstMonoGameProject \bin\Debug\netcoreapp3.1\Content\Graphic\CoolBox'.'
Код, в котором появляется ошибка< /p>
public Texture2D LoadTexture()
{
string fullPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)
+ "/Content/Graphic/" + "CoolBox";
using (FileStream fileStream = File.Open(fullPath, FileMode.Open))
{
Texture2D myTexture2D = Texture2D.FromStream(EntityManager.graphicsDevice, fileStream);
return myTexture2D;
}
}
Дополнительный код, в котором я вызываю метод (оба из игры1)
protected override void LoadContent()
{
spriteBatch = new SpriteBatch(GraphicsDevice);
coolBox.LoadTexture();
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
spriteBatch.Begin();
spriteBatch.Draw(coolBox.LoadTexture(), new Rectangle(0, 0, 280, 210), Color.White);
spriteBatch.End();
base.Draw(gameTime);
}
Подробнее здесь: https://stackoverflow.com/questions/692 ... dexception