Forum Xamarin.Android

Texture2d Content Loading

Using MonoGame, I've been trying to load content by using the commong Content.Load("Dir/contentfile"), and had success at first. I added my png files to the content directory, set them to build action 'Content', and set them to Copy If Newer.

After adding more content, however, I kept getting the "could not add as a non-content file" exception. I confirmed their build actions, cleaned, and rebuilt the solution with no luck. It is my understanding that this is possible (not compiling the content for MonoGame and using the png files), and also it worked correctly for some of the files.

I am using the Xamarin IDE. Google solutions have offered no help so far, any insights on things I could try? Is this simply a MonoGame issue?

I've:

  • used the full name with and without filename endings (Load("Dir/contentfile.png")
  • tried other build actions such as 'AndroidAsset'
  • Ensured they are being copied to the bin folder after building and they in the correct content directory
  • Completely deleting the bin\obj folders and rebuilt

Posts

  • RyanHallRyanHall USMember

    Well I couldn't figure out how to load it from the Content.Load() method, but my work around was:

    1. Add a content folder in the activity project's Asset folder called Content

    2. Add all png files there (I added them as links)

    3. Set build action to AndroidAsset

    4. Use a simple helper function to load assets:

    public static Texture2D LoadTexture(GraphicsDevice dev, string name) { using(var stream = Game.Activity.Assets.Open(name)) { return Texture2D.FromStream (dev, stream); } }

Sign In or Register to comment.