7. States

Introduction

Gum supports the concept of states, which are very similar to states in Glue. This tutorial will discuss how to use States which are created in Gum when integrating Gum objects in Glue.

This tutorial will cover both regular (uncategorized) as well as categorised states.

If you’d like to see how to work with states in Gum, see this tutorial.

If you’d like to see how to work with categorised states in Gum, see this tutorial.

Since the tutorials shown above do a good job of walking you through how to create states and categories this tutorial will assume you understand these concepts and will skip over setting up a component. This tutorial will use the CategoryDemoScreen and CategoryDemo set up in the category state tutorial listed above.

Adding a Screen in Glue

Just like with previous tutorials you will need to have a Gum project added to your Gum project, and you should have a Glue screen which references the CategoryDemoScreen from Gum. If you have set this up correctly then you should see a CategoryDemo component instance on screen when you run your game:

GumBigBlueInFrb.PNG

Controlling States in Code

So far we have shown that any states which are set (including categorised states) will properly show up in our game. We can also change the state of instances at runtime. For this example, we’ll change the state of the CategoryDemoInstance with keys presses.

To do this, we need to get access to the CategoryDemoInstance object in Glue. The steps are:

  1. Right-click on your Screen’s Objects
  2. Select “Add Object”
  3. Select “From File”
  4. Select the CategoryDemoScreen.gusx file (or the name of your Gum screen)
  5. Select “CategoryDemoInstance” (or the name of your instance)
  6. Type the name CategoryDemoInstance (or whatever name you’d like to have for your object in Gum)

Now this can be modified in code. To do so, add the following code to your Screen’s CustomActivity:

AfterStateSetOnGumInCode.PNG

<- 6. Exposed Variables — 8. Adding Code to Gum Objects ->