Using a resource file (resx)

I want to use a resx file to call all of my game content and resources (sound, images, sprites,ect...). How do you call the resx file in you classes and how do you let the classes know what files you want to use

Thanks ahead of time.



Answer this question

Using a resource file (resx)

  • ititrx

    Joel Martinez wrote:
    Well, the easiest way that you can get files embedded into your EXE is by simply setting the build action to "Embedded Resource". However, this requires that you do all of your own content parsing and loading at runtime because you won't be able to use the content pipeline ... this also means that it won't work on the 360.

    If you want it to work with the 360, then you can easily create a custom ContentManager and override the OpenStream method to use the resource classes instead of File IO. However, there's still an issue there because content like textures and models won't get a chance to go through the content pipeline.

    Now, I'm not sure if this would work as I just cooked it up right now ... but theoretically, it should be possible to build your content in a separate process using (XCB), then adding the resulting .xnb content files to your project as embedded resources, then using the custom content manager to load the XNB content from resources.

    There is already a specialized content manager for loading resources included with XNA. The class is called ResourceContentManager and it does exactly what you suggest. It expects the .xnb files to be added as resources (not the source assets).

    Cheers,
    Leaf.



  • John.Q.Francis

    Well, the easiest way that you can get files embedded into your EXE is by simply setting the build action to "Embedded Resource". However, this requires that you do all of your own content parsing and loading at runtime because you won't be able to use the content pipeline ... this also means that it won't work on the 360.

    If you want it to work with the 360, then you can easily create a custom ContentManager and override the OpenStream method to use the resource classes instead of File IO. However, there's still an issue there because content like textures and models won't get a chance to go through the content pipeline.

    Now, I'm not sure if this would work as I just cooked it up right now ... but theoretically, it should be possible to build your content in a separate process using (XCB), then adding the resulting .xnb content files to your project as embedded resources, then using the custom content manager to load the XNB content from resources.


  • GAtkins

    As far as I know you cannot use the resx resource reader with the xna framework, if writing a game only for windows you can reference the appropriate dll and use all the features of the resx file.

    The xna framework does support the .resources file reader and the resource manager.

    storage in the resx file is in xml format and the schema is available, so if ambitious you can write your own reader and implement the ResourceReader interface.

    here are a few helpfull links on how to work with a resource files:


    http://www.codeproject.com/useritems/net_Resource_Editor.asp

    http://samples.gotdotnet.com/quickstart/howto/doc/useresources.aspx

    http://msdn2.microsoft.com/en-us/library/system.resources.resourcemanager.aspx

    http://msdn2.microsoft.com/en-us/library/ekyft91f(VS.80).aspx

    http://msdn.microsoft.com/library/default.asp url=/library/en-us/cpguide/html/cpconResourcesInResxFileFormat.asp



  • j_johnso

    I have achived embedding resources and am using it for my console component to store the console iamge and default font.

    Anyways im gona do a quick tutorial on it and post it later tonight for you. hope it helps



  • DavidThi808

    Embedding all your content in an assembly resource may be okay for a Windows game, but you probably do not want to do that for Xbox 360 games. The NetCF runtime loads the entire assembly before it is JIT-compiled, meaning that *all* of your game content will be loaded at once when the assembly is loaded, then loaded again as you deserialize the resources into objects.

    If you're creating a small game, this will be no problem. However, if you are building a game with multiple levels, or one with many resources, or one that aggressively uses memory, then you will probably want to load that content only when you need it. In that case, embedding it in a resource is not a good way to go.

    Again, this only applies to Xbox 360.

    --Stephen


  • willajo

    I definitely think it's never a good idea to embed all resources into the assembly/executable. However, it might be handy for 3rd party libraries that rely on a certain shader or texture being available for example. Doing this would simplify distribution since the developer just has to reference the assembly and off they go :-)


  • Bob Lyden

    Ok tutorials done, its quick but covers everything.

    http://www.plasmaflux.com/Tutorials/Embedded/Embedded.htm

    P.S

    also has a demo project.

    http://www.plasmaflux.com/Tutorials/Embedded/Embedded.zip



  • Ashtom

    I have just finished the development of a free tool that I call ResEx, composite, translation friendly resource editor for .NET.
    It is a free tool and I intend to keep it free, containing all current features. A small charge may be applied for some features I may introduce later, just to help me keep supporting and enhancing the project.
    I encourage you to download ResEx and post any suggestions to the discussions page you can find under Help menu of the application. Info and download
    Here is a list of features provided by ResEx:6
    • Translate values side by side (just like the old time classic VB6 resource editor)
    • Lock specific strings so that translator does not translate them
    • Ensure correct translation of strings with placeholders {0} {1} ...
    • View resource strings in tree form
    • Translate resources without Visual Studio IDE
    • Search inside resource files while translating
    Regards


  • Using a resource file (resx)