Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Game configuration in C# and XNA

What is the simplest way to read and write game configurations like: whether to show fps or play sound, etc.

Maybe there are some class in xna that can be used to do that?

I don't really want to use default C# XML thingy for an XNA game.

like image 891
NewProger Avatar asked Jan 24 '12 07:01

NewProger


People also ask

How do I assign a default configuration file to a game?

Alternatively, MicrosoftGame.config files can be assigned to configurations by editing the project file directly. Use the DefaultApplyTo element of the MGCCompile property to specify a default MicrosoftGame.config file. This default file will be used for all configurations unless explicitly overridden.

What is microsoftgame config used for?

It's used during the packaging of your game for ingestion and publishing through Microsoft Store, as well as for registering information about the game during local iteration on loose-file builds during game development. This topic explains the purpose and use of MicrosoftGame.config, as well as its relationship to AppXManifest.xml.

How to configure Microsoft Game config for Xbox One games?

Set your configuration to the "Gaming.Xbox.XboxOne.x64", "Gaming.Xbox.Scarlett.x64" or "Gaming.Desktop.x64" platform. Add the MicrosoftGame.config file for your game as a file in your Visual Studio project. In the properties for the MicrosoftGame.config file, set Item Type to Microsoft Game Config, shown as follows.

Can you make a game with C++?

Anyone who’s even taken a passing interest in game development knows how influential Unreal and Unity have been to game makers. On top of that, most game engines can use C++ as well, making it possible not only to develop a game engine, but a game to run off of it.


2 Answers

I'd like to propose a much simpler answer. I assume these configuration changes are only for testing during development right? Then why not simply have a static class with your settings:

public static class Debugging
{
  public static bool ShowFPS = true;
  public static bool PlaySound = false;
}

This way, you don't have to write any code for reading the values from disk. All you have to do is something like if (Debugging.ShowFPS). You also don't have to write any code to change the values at runtime other than setting a static field (Debugging.ShowFPS = false;).

Think about it, if you store your values in, say, an XML file, your work flow will be:

  1. Open file
  2. Change value
  3. Press F5 to run the game with the changed values

the workflow is exactly the same, with the added benefit that you don't have to write any code to deal with reading and writing. It also works with absolutely no changes on all supported platforms. And if you want to be 100% sure that you don't forget to change a setting before releasing, you can use a simple ifdef with the correct values for production:

    public static class Debugging
    {
#if DEBUG
      public static bool ShowFPS = true;
      public static bool PlaySound = true;
#else
      public static bool ShowFPS = false;
      public static bool PlaySound = false;
#endif
    }

Sometimes, the best answer is the simplest ;-)

like image 131
Joel Martinez Avatar answered Oct 17 '22 11:10

Joel Martinez


Since you've mentioned that you might want to port to the xbox, i'd recommend using a library called EasyStorage. It's what a lot of people use when doing simple reading/writing.

It deals with allowing the player to choose their storage device (if more than one exist) and with things like the player removing the storage device before trying to save etc. It'll give you a Stream to save/load from, so most of your actual saving/loading code will be the same.

like image 41
George Duckett Avatar answered Oct 17 '22 10:10

George Duckett