Welcome to a quick guide to get you started using BlackStar.

This guide was written for use with Release 0.1.0, Microsoft Visual C# Express 2008, and XNA Game Studio 3.0. Please be sure that you have a recent version of Visual C# installed along with a recent version of XNA Game Studio before continuing.

In order to continue, you will need to download the x86 version of the release. Alternatively, you may prefer to download the source code version and compile your own assemblies.

Start by opening Visual C# and creating a new project using the Windows Game (3.0) template.

Next add a reference to the BlackStar.dll assembly to the project.

Add a Content Reference to the BlackStarPipeline.dll assembly. This is needed so that the XML content used to define your GUI can be compiled into .xnb files.

Add a new folder to the content of your project called 'GUI'.

To this folder there are a few files that need to be added in order to render a gui. The simplest way to do this is to copy the contents of the GUI folder from the Release Zip archive into the newly created GUI folder.

At this point, a theme has been added. The theme contains all the files needed to render the GUI, including Sprite Fonts and Cursors. The KeyMapDefault.XML file contains data that convert keyboard codes to an appropriate display character. Last the GUI.XML file contains a simple gui for purposes of this guide.

Now you are ready to start writing some code. Open up the game1.cs file that was created when the project was created. At the top of the Game1 class declare a variable to hold the GUI like this:

BlackStar.GUI gui;

Now some code is needed to create an instance of the GUI.

gui = new BlackStar.GUI(this, "GUI\\GUI", "GUI\\Themes\\Default\\Theme",  "GUI\\KeymapDefault");

Lets explain the parameters in the above code. First of a BlackStar GUI is a Drawable Game Component. It ancestor class requires a Game so we provide the instance of the Game1 class.

Second, the GUI needs an XML content file that contains instructions about what forms and controls to draw, so the second parameter points to the GUI.xml file, since the XML will be compiled into an .xnb file we don't specify the .xml extension.

The third parameter is to another XML content file. This time the parameter points to the Theme.xml file which contains instructions on how to use all the textures needed to draw the GUI.

The fourth parameter is for yet another XML content file, the Keymap file.

If you run the code now, you should see a Login Dialog.

Last edited Feb 10, 2009 at 5:14 PM by wleader, version 1

Comments

MercuryBD Aug 6, 2010 at 10:05 AM 
@ledpup

try this, it works for me :)

using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace GUI
{
/// <summary>
/// This is the main type for your game
/// </summary>
public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
BlackStar.GUI gui;

public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}

/// <summary>
/// Allows the game to perform any initialization it needs to before starting to run.
/// This is where it can query for any required services and load any non-graphic
/// related content. Calling base.Initialize will enumerate through any components
/// and initialize them as well.
/// </summary>
protected override void Initialize()
{
// TODO: Add your initialization logic here

base.Initialize();
}

/// <summary>
/// LoadContent will be called once per game and is the place to load
/// all of your content.
/// </summary>
protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);


gui = new BlackStar.GUI(this, "GUI\\GUI", "GUI\\Themes\\Default\\Theme", "GUI\\KeymapDefault");
gui.Initialize();

// TODO: use this.Content to load your game content here
}

/// <summary>
/// UnloadContent will be called once per game and is the place to unload
/// all content.
/// </summary>
protected override void UnloadContent()
{
// TODO: Unload any non ContentManager content here
}

/// <summary>
/// Allows the game to run logic such as updating the world,
/// checking for collisions, gathering input, and playing audio.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Update(GameTime gameTime)
{
// Allows the game to exit
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();

gui.Update(gameTime);

base.Update(gameTime);
}

/// <summary>
/// This is called when the game should draw itself.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);

spriteBatch.Begin();

gui.Draw(gameTime);

spriteBatch.End();
base.Draw(gameTime);
}
}
}

You need to initialize, update and draw the gui :)
I just started to use this lib, so I hope this helps :)

ledpup Mar 10, 2009 at 11:12 PM 
Hi.

I just tried to start-up your API following the instructions above. I get a "System.NullReferenceException, Object reference not set to an instance of an object." on the "base.Update(gameTime);" line. I put the "gui = new BlackStar.GUI(this, "GUI\\GUI", "GUI\\Themes\\Default\\Theme", "GUI\\KeymapDefault");" line in the Initialize method. I've checked the dll references and I copied the GUI folder into the Content folder and included it in the project. Do I need to do anything more with the GUI folder?

Any other ideas?