Running In MonoGame - LiruJ/GuiCookie GitHub Wiki

Overview

Now with the XML set up, it is time to actually get something displaying on screen.

This section assumes you have completed the last two steps within a MonoGame project, and have the latest version of GuiCookie set up via NuGet.

Creating the UI

Add a new class to your project, in this example it will be named "TestRoot". It should implement the "Root" class, and for now is left empty. It should look like this:

using GuiCookie;

public class TestRoot : Root 
{

}

Within your main Game1.cs class (or whatever you have renamed it), add three new variables:

private UIManager uiManager;

private TestRoot testRoot;

private GuiCamera camera;

Now within the LoadContent() function, these variables can be safely set up.

The UIManager allows roots to be easily created without needing to supply every single dependency, it takes a Game object in its constructor.

uiManager = new UIManager(this);

The GuiCamera handles drawing the elements, the UIManager can create one easily.

camera = uiManager.CreateGuiCamera();

Now the UI itself can be set up. Note that the path is to the layout sheet made in the last section, relative to the content folder.

testRoot = uiManager.CreateUIRoot<TestRoot>("Gui\\Layout");

The UI has been loaded and set up by this point, but it still needs to be drawn and updated.

Add this to the Update(GameTime) function:

testRoot.Update(gameTime);

Add this to the Draw(GameTime) function:

camera.Begin();

testRoot.Draw(camera);

camera.End();

And now if you build and run, you should see a text box in the top-left corner that says "Hello World!".

Next Steps

Now that there's a GUI being drawn and updated, the next step is to add some form of interaction between the player and the code by adding buttons.

⚠️ **GitHub.com Fallback** ⚠️