This project is read-only.

Content Folder location

Topics: Content Building and Deploying
Oct 12, 2013 at 11:21 AM
Edited Oct 12, 2013 at 11:59 AM
Hello all

I can't seem to figure out something about the location of the Content Folder.

Basically I have made a simple app (iOS) based on this tutorial:

But for my app, I need to download content from a server at runtime.

Where do I place that content?

I noticed that with the line below one can set de default content folder (in my case I that is mapped to the Content folder in de app bundle)

this.Content.RootDirectory = "Content";

I then created a "Content" folder in "Documents" folder of my app and download my content.

If I then set the RootDirectory to the absolute path of this new folder nothing seems to work.

I have checked: my new folder exists and all content is present.

Strangely, sounds do work, but fonts and graphics are not loaded.

How can I make Cocos2D-xna work with downloaded content?
  • I have tried to load the graphics with an absolute path, with or without .png extension, but that does not work either.
  • I have tried to load the texture cache with an image based on an absolute path, but that does not work either.
Thank you for your help


Oct 12, 2013 at 11:58 AM
Edited Oct 12, 2013 at 11:59 AM
Well, checking out MonoGame, I found this :
        static TitleContainer() 
            Location = AppDomain.CurrentDomain.BaseDirectory;
#elif WINRT
            Location = Windows.ApplicationModel.Package.Current.InstalledLocation.Path;
#elif IOS || MONOMAC
            Location = NSBundle.MainBundle.ResourcePath;
#elif PSM
            Location = "/Application";
            Location = string.Empty;

#if IOS
            SupportRetina = UIScreen.MainScreen.Scale == 2.0f;

        static internal string Location { get; private set; }
#if IOS
        static internal bool SupportRetina { get; private set; }
Seems like a if you use TitleContainer to get the absolute path of a file, it is always prepended with the NSBundle resource path

It would be great if the private setter of "Location" was made public so we can set it to empty ...

Even beter would be a solution where there are possibly more Content folders .. one for content that is embedded in the app, and one for content that has been downloaded?

Maybe such a system already exists and I'm not aware of? Cocos2D-XNA and MonoGame are rather new to me



Oct 15, 2013 at 5:39 AM
You have to use the FromStream() methods to create textures from outside of the title container. The title container exists to maintain compatibility across a variety of platforms that require sandbox installations. You can write into the title container location, so if you download content, just download it to a location in the title container directory. Then you can load it from stream.
Oct 15, 2013 at 11:23 AM
I have submitted an issue yesterday with more information about the matter...
Your suggestion does not solve problems with fonts ... creating fonts from .ttf has been hardcoded to use the Bundle Resource path on iOS (not checked what happens on other platforms).

I'm currently working on a non-breaking solution that uses more than one RootDirectory

I have created:
        private List<string> _rootDirectories = new List<string> ();

        public List<string> RootDirectories
                return this._rootDirectories;

                if (value == null) 
                    this._rootDirectories = new List<string> ();
                    this._rootDirectories = value;
When RootDirectory is set to null, I will walk RootDirectories (everywhere in code where RootDirectory is used) and return the first file / stream that matches the search and exists.Changes are made in MonoGame and in Cocos2D, but do not break existing code.
This way I can use both embedded content and content that has been downloaded to the (for example) documents or cache folder.
Oct 29, 2013 at 5:10 PM
Your solution follows how the search path works in cocos2d-x.

Maybe there is a way to provide a better search path strategy for MonoGame that pulls content outside of the TitleContainer.