ContentLoadException в Monogame для Android - PullRequest
0 голосов
/ 24 октября 2019

Я не могу загрузить изображения в Monogame для Android с помощью Xamarin и получаю следующее исключение:

ExceptionMicrosoft.Xna.Framework.Content.ContentLoadException: содержимоефайл не найден.

Я изменил файлы на «Копировать, если новее» и «Актив Android» и добавил их как в ресурсы, так и в контент. Я также подтвердил, что при использовании конвейера Monogame файл «WowperroFirmaWhite.xnb» создается в «bin \ Android \ Content».

Я слежу за этой моногейкой видео-учебник ;Я также пытался загрузить изображение в новый проект, но все еще не могу.

Это мой Solution Explorer

Solution Explorer Screenshot.

И последнее, ноНе в последнюю очередь - вот мой код

 public class SplashScreen : GameScreen
    {
        Texture2D image;
        string path;
        public override void LoadContent()
        {
         try
            {
                path = "WowperroFirmaWhite";
                image = content.Load<Texture2D>(path);               
            }
            catch(Exception e)
            {
                Console.WriteLine("EXCEPTION");
                Console.WriteLine(e);
            }
        }

Я также установить

 public class GameScreen
    {
        protected ContentManager content;
        public virtual void LoadContent()
        {
            content = new ContentManager(ScreenManager.Instance.Content.ServiceProvider, "Content");
        }

И на главной

 public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";

            graphics.IsFullScreen = true;
            graphics.PreferredBackBufferWidth = 800;
            graphics.PreferredBackBufferHeight = 480;
            //graphics.SupportedOrientations = DisplayOrientation.LandscapeLeft | DisplayOrientation.LandscapeRight;
            graphics.SupportedOrientations = DisplayOrientation.Portrait;
        }

Тогда

protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);
            ScreenManager.Instance.LoadContent(Content);
        }

И на ничьей

protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            spriteBatch.Begin();

            ScreenManager.Instance.Draw(spriteBatch);

            spriteBatch.End();  

            base.Draw(gameTime);
        }

В моем контенте.mgbc

#----------------------------- Global Properties ----------------------------#

/outputDir:bin/$(Platform)
/intermediateDir:obj/$(Platform)
/platform:Android
/config:
/profile:Reach
/compress:False

#-------------------------------- References --------------------------------#


#---------------------------------- Content ---------------------------------#

#begin WowperroFirmaWhite.png
/importer:TextureImporter
/processor:TextureProcessor
/processorParam:ColorKeyColor=255,0,255,255
/processorParam:ColorKeyEnabled=True
/processorParam:GenerateMipmaps=False
/processorParam:PremultiplyAlpha=True
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:WowperroFirmaWhite.png

Если вы хотите увидеть полный проект, вот мое решение на Github

...