Search code examples
c#monogame

Monogame Load Content Without Content.mgcb and Content.Load()


I am trying to make a program that needs to load texture and sound contents from a file that is not compiled in the content manager or Content.mgcb file in C# with MonoGame 3.6. Players would be able to find the directory and replace the content files that need to be loaded after the program is installed on their phones or desktop computers. How can I do that?


Solution

  • Textures:

    • Texture2D.FromStream
    • Load texture data from some source(file/network/etc), converting to the format you desire as an array(i.e. byte[], Color[]). Construct a new Texture2D with the dimensions and format of the data. Upload to the texture with SetData.

    Audio:

    • Song.FromUri
    • SoundEffect.FromStream
    • Load sound data from some source(file/network/etc), extracting the metadata(sample rate/loop info/etc), then converting to PCM. Construct a new SoundEffect with the PCM data and metadata.
    • Use an alternate framework for audio(i.e. Bass(win/osx/linux), FMOD(most platforms)).

    Fonts: