Monday 2 July 2012

RandomChaos GSM Library



Well, here is the first "Alpha" of my GSM. I have not supplied an example project with this release but there is a word doc and a help file in the help folder to get you started.

Basically you have a screen manager object that you add screens to, these screens have screen items that you add to the screens and once you have got all that in place you just add the screen manager to the Game.Components and away you go.

Here is a quick and very simple example:
// Create a screen manager.
RandomChaos.GameStateMenuSystem.ScreenManager screenManager = newRandomChaos.GameStateMenuSystem.ScreenManager(this);
// Create a menu instance
RandomChaos.GameStateMenuSystem.BaseMenuScreen menu = newRandomChaos.GameStateMenuSystem.BaseMenuScreen(this);
// Give it a name and a background image and switch on the bloom effect.
menu.ScreenName = "MenuScreen";
menu.AddBackgroundImage("Textures/steel2");
menu.Bloom = true;
// Set up a menu item.
menuItem.ForeColor = Color.White;
menuItem.FontAsset = "Fonts/test";
menuItem.TextureAsset = "Textures/perlin";
menuItem.Text = "Exit";
menuItem.SetAction(RandomChaos.GameStateMenuSystem.SelectAction.Exit, null);
menuItem.ImageTileSize = 2;
// Give the menu item a shadow.
menuItem.ShadowDepth = 2;
menuItem.ShadowColor = Color.Black;
// Add key/buttons to handle menu navigation.
menu.AddScreenExitInput(Keys.Escape);
menu.AddMenuSelectInput(Keys.Space, Keys.Enter);
menu.AddMenuSelectInput(Buttons.A, Buttons.Start);
menu.AddMenuDownInput(Keys.Down);
menu.AddMenuDownInput(Buttons.DPadDown, Buttons.LeftThumbstickDown);
menu.AddMenuUpInput(Keys.Up);
menu.AddMenuUpInput(Buttons.DPadUp, Buttons.LeftThumbstickUp);
// Add the menu item
menu.AddMenuItem(menuItem);
// Add the menu to the screen manager.
screenManager.AddScreen(menu);
// Add the manager to the game.Components.
Components.Add(screenManager);


As you can see it is pretty simple to get a GSM up ans running with this (don't forget to add the library as a reference to your project!), have a go and see what you can come up with. Naturally for your game you will want a menu option to take you to your game class. To do this simply create your game class and derive from BaseScreen, you can then add your game class to the screen manager and then have it called from the menu item by setting the menu items Action to GoTo and the action screen to an instance of your game class by using the menu items SetAction method. Take a look at the help file for more info on this function.

I still have a few optimizations to make. As ever C&C are welcome, also if you have any effects or transitions you would like to see in the GSM, post them up here and I will do my best to get them in.

This is a full content version too so you wont have to set up a default font or have your own perlin and displacement map textures, but if you want to swap these items for your own then by all means do. It is also only for the PC, I have created and tested it on the 360 and all went well,but I probably wont do a full 360 version until I have this at first release, I guess if you ask me for it though, I could build it and put it up.

The download for this is here.

No comments:

Post a Comment