How to assign a folder that should be referenced for any files needed C#,XNA

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • EARNEST
    New Member
    • Feb 2010
    • 128

    How to assign a folder that should be referenced for any files needed C#,XNA

    Hello there,

    I've got a bit of a problem. XNA allows to use XML files, however, it will serialize them into XNB, so the only chance I can edit them is at design-time, not run-time. That is why, I decided to use a normal .NET serialization/deserialization . However, how do I set a folder for all my textures, audio and other files?
    As an example of what I want is:
    Code:
    //pseudo code
    
    entity.Deserialize("/textures/ship/ship.xml");
    classInstance.Load("audio/battle/fight1.mp3");
    ...
    //so on
    Should I just create a given folder in the Debug/Release folder? Is it a good approach?
    Thanks in advance
  • EARNEST
    New Member
    • Feb 2010
    • 128

    #2
    Should I use resource.resx file for such purpose?

    Comment

    • GaryTexmo
      Recognized Expert Top Contributor
      • Jul 2009
      • 1501

      #3
      If I'm understanding you correctly, yea I'd probably do it that way too. Keep everything ni a folder and reference it like that. However, it's kind of a pain to keep everything in both folders like that, it would be much easier to keep them in the folder for your project.

      You can use post-build operations in Visual Studio to copy a folder to your build destination so that you'll always have these files there, but can maintain them in another location.

      If that's not what you meant, sorry :(

      Comment

      • EARNEST
        New Member
        • Feb 2010
        • 128

        #4
        Is there a button for quote-tag? :) lol
        anyways,
        You can use post-build operations in Visual Studio to copy a folder to your build destination so that you'll always have these files there, but can maintain them in another location.
        could you please give more details on this, if you don't mind?
        What I think I'm going to do is
        1. Create a resource manager (.resx file)
        2. Create a string element in it with a given folder name, e.g. string1 = "texture", string2 ="ship" and so on
        3. When I would need to reference a destination folder from where my asset manager should load .xml files and other thingies, i'd do something like myResManager.st ring1 and so on

        While creating folders in the Debug and/or Release folder with respective names (string1...N string values) from the .resx file. Hope I managed to clarify my issue a bit. If that's not what you understood by my initial post, pls, let me know.

        Comment

        • GaryTexmo
          Recognized Expert Top Contributor
          • Jul 2009
          • 1501

          #5
          For build events, have a look here: http://geekswithblogs.net/dchestnutt.../30/80113.aspx

          You can use this to copy your custom content folder to the build destination so you only have to maintain a single directory structure.

          For the other part... correct me if I'm wrong here, but are we talking this sequence of events at program run time?
          1. Program starts
          2. Program reads resx file
          3. For each line in the resx file, program loads an asset (from the supplied relative file path)


          If that's correct, yea that would work just fine :) I'm not sure what of this is automated though... as I said in the other thread, I don't know this that well, so if I'm not much help I'm sorry.

          Comment

          • EARNEST
            New Member
            • Feb 2010
            • 128

            #6
            Thanks for the link. i`ll look into it.
            Nope, not at program run time. At design time.
            Treat it as a class with some properties that would act as dest. folders. I don't know what kind of behaviour resx files exhibit at run-time.

            Comment

            • GaryTexmo
              Recognized Expert Top Contributor
              • Jul 2009
              • 1501

              #7
              Ah all right, well I guess you can do that. If you're not using this info at run-time then I'm not entirely sure why you want a resx file. The point of them is so you can change info without having to build your code again. If you're going to use it like a class, you might as well just hard code it as a list of constants...?

              That said, why not let it read the resx file at runtime and load the content accordingly?

              Comment

              • EARNEST
                New Member
                • Feb 2010
                • 128

                #8
                i was trying to do something like that. instead of reading the resx file at runtime, the resx file at design/compile time would define the settings.xml file, in return, at run-time, the settings.xml file would then point to the respective content....does it make sense?

                Comment

                • EARNEST
                  New Member
                  • Feb 2010
                  • 128

                  #9
                  P.S.This states that .resx is incorporated in the executable or library file, so... i don't think i could make use of it at run time

                  Comment

                  • GaryTexmo
                    Recognized Expert Top Contributor
                    • Jul 2009
                    • 1501

                    #10
                    Hmm, I guess I'm thinking of something else entirely. My experience with resx files was for use with localization, so these files could be changed outside of the program allowing us to change languages without a recompile.

                    Is this resx file acting as defaults then? I don't really understand why else you'd need both.

                    Comment

                    • EARNEST
                      New Member
                      • Feb 2010
                      • 128

                      #11
                      so, if the resx file , in a way, is hard-coded at compile-time, i can use regular hard-coded values in my classes...?

                      Comment

                      • GaryTexmo
                        Recognized Expert Top Contributor
                        • Jul 2009
                        • 1501

                        #12
                        Maybe someone else can answer that question in a better way. To me I'm not seeing a difference.

                        To me though, why don't you just put everything in your settings.xml and be done with it? Reference everything by name in your program and have your settings.xml file populate the list to supply those names with data.

                        That's me though...

                        Comment

                        • EARNEST
                          New Member
                          • Feb 2010
                          • 128

                          #13
                          Then, I'd need to hard-code the name "settings.x ml" in my program (to associate it). Anyways, thanks a lot

                          Comment

                          • GaryTexmo
                            Recognized Expert Top Contributor
                            • Jul 2009
                            • 1501

                            #14
                            You would, but that's not a bad thing...

                            Comment

                            Working...