Setup
Last updated
Was this helpful?
Last updated
Was this helpful?
This tutorial walks you through creating an empty Gum project which acts as a starting point for the rest of the tutorials.
This tutorial covers:
Adding Gum NuGet packages
Modifying your Game class to support Gum and Gum Forms
Adding your first Gum control (Button)
Before writing any code, we must add the Gum nuget package. Add the Gum.MonoGame package to your game. For more information see the Setup page.
Once you are finished, your game project should reference the Gum.MonoGame
project.
Gum requires a few lines of code to get started. A simplified Game class with the required calls would look like the following code:
The code above includes the following sections:
StackPanel mainPanel - Games using Gum usually have an object which contains all other instances. In this case we create a StackPanel which will hold all of our controls.
Initialize - The Initialize method prepares Gum for use. It must be called one time for every Gum project. Once Gum is initialized, we can create controls such as the StackPanel. By calling AddToRoot, the maniPanel will be drawn and will receive input. All items added to the StackPanel will also be drawn and receive input, so we only need to call AddToRoot to the StackPanel.
Update - this updates the internal keyboard, mouse, and gamepad instances and applies default behavior to any components which implement Forms. For example, if a Button is added to the Screen, this code is responsible for checking if the cursor is overlapping the Button and adjusting the highlight/pressed state appropriately. We pass the Root instance so that it and all of its children can receive input events.
Draw - this method draws all Gum objects to the screen. This method does not yet perform any drawing since StackPanels are invisible, but we'll be adding controls later in this tutorial.
We can run our project to see a blank (cornflower blue) screen.
Now that we have Gum running, we can add controls to our StackPanel (Root). The following code in Initialize adds a button which responds to being clicked by modifying its Text property: