# How to make a game start menu in Processing?

**URL:** <https://discourse.processing.org/t/how-to-make-a-game-start-menu-in-processing/6019>\
**Category:** Coding Questions\
**Created:** [November 28, 2018, 5:44am UTC](https://discourse.processing.org/t/how-to-make-a-game-start-menu-in-processing/6019 "2018-11-28T05:44:14Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![CyanNi](https://avatars.discourse-cdn.com/v4/letter/c/34f0e0/32.png) [@CyanNi](https://discourse.processing.org/u/CyanNi)\
**Post date:** [November 28, 2018, 5:44am UTC](https://discourse.processing.org/t/how-to-make-a-game-start-menu-in-processing/6019/1 "2018-11-28T05:44:14Z")

</div>

Hello!  
I’m to trying to make a game, but I want to create a game start menu. I’ve looked at other forums, and I just feel confused??  
Can someone ELI5 for this?

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [November 28, 2018, 6:05am UTC](https://discourse.processing.org/t/how-to-make-a-game-start-menu-in-processing/6019/2 "2018-11-28T06:05:46Z")

</div>

i am not sure what you need,  
as a **menu** might be lots of code…  
possibly you talk about a easy structure like  
mode …  
and a operation concept to change that mode  
( like hit a key [n] to go to next mode )

so do you talk about that?

```auto
// https://discourse.processing.org/t/how-to-make-a-game-start-menu-in-processing/6019

int mode = 0;

void setup() {
  println("click on canvas and use key [n] for next level");
  println("mode: "+mode);
}

void draw() {
  switch(mode) {
  case 0:
    // here your code for this mode
    break;
  case 1:
    // here your code for this mode
    break;
  case 2:
    // here your code for this mode
    break;
  default:
    println("you should never see this");
    break;
  }
}

void keyPressed() {
  if ( key == 'n' ) mode++;
  if ( mode > 2 ) { 
    println("reset"); 
    mode = 0;
  }
  println("mode: "+mode);
}

```

now a start menu would be much more code  
while in “mode 0”

---

<div class="post-metadata">

**Author:** ![djokjula](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/djokjula/32/2544_2.png) [@djokjula](https://discourse.processing.org/u/djokjula)\
**Post date:** [November 28, 2018, 9:45am UTC](https://discourse.processing.org/t/how-to-make-a-game-start-menu-in-processing/6019/3 "2018-11-28T09:45:36Z")

</div>

I suggesting making two functions: `drawMenu()` and `drawGame()`, and a variable `int screenState`.  
In `drawMenu()` you create your “play”, “load”, “exit” buttons, and in `drawGame()` you write what you would in `draw()` wen you didn’t have the menu.  
Whit those functions finished, you call them in `draw()` based on `screenState`, something like this:

```auto
final int MENUSCREEN = 0;
final int GAMESCREEN = 1;
// setup() and other global variables
void draw() {
  if (screenState == MENUSCREEN) {
    drawMenu();
  } else if (screenState == GAMESCREEN) {
    drawGame();
  } else {
    printlin("Something went wrong!");
  }
}

void drawGame() {
  // Pew, pew, I'm a game!
}

void drawMenu() {
  // Don't forget to save :D
}

```

Remember to set `screenShtate` to `0` in `setup()`!

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [November 28, 2018, 12:23pm UTC](https://discourse.processing.org/t/how-to-make-a-game-start-menu-in-processing/6019/4 "2018-11-28T12:23:10Z")

</div>

> [@djokjula](#):
>
> Remember to set _screenState_ to `0` in **setup()**!

Given the datatype of the field _screenState_ is `int`, its default value is already `0`. 😋  
Which btW, corresponds to the same value as the constant MENUSCREEN. 😉

> **[Primitive Data Types (The Java™ Tutorials \>        
            Learning...](https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html)**
>
> This beginner Java tutorial describes fundamentals of programming in the Java programming language

Also, we can explicitly give an an initial value to the field _screenState_ at the same time we declare it. 🤓  
No need to wait till **setup()** in order to do so. 🚏

```auto
static final int MENUSCREEN = 0, GAMESCREEN = 1;
int screenState = MENUSCREEN;

void setup() {

```

---

<div class="post-metadata">

**Author:** ![djokjula](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/djokjula/32/2544_2.png) [@djokjula](https://discourse.processing.org/u/djokjula)\
**Post date:** [November 28, 2018, 3:12pm UTC](https://discourse.processing.org/t/how-to-make-a-game-start-menu-in-processing/6019/5 "2018-11-28T15:12:46Z")

</div>

I agree with the initialization, I’m used to C++ so some things bleed to my Processing, and it helps me debug some NullPointerExceptions 😃

> [@GoToLoop](#):
>
> Also, we can explicitly give an an initial value to the field _screenState_ at the same time we declare it.

Although It might be better to use setup for all initialization, because you can then restart the sketch just by calling `setup();`. 🤓

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [November 28, 2018, 3:44pm UTC](https://discourse.processing.org/t/how-to-make-a-game-start-menu-in-processing/6019/6 "2018-11-28T15:44:54Z")

</div>

> [@djokjula](#):
>
> … because you can then restart the sketch just by calling **setup()**.

Both **setup()** & **settings()** should only be run once, called back automatically by the “Animation” Thread. ❎

If a sketch restarting is desired, we can always make our own **restart()** function. 💡

---

<div class="post-metadata">

**Author:** ![Sky\_119](https://avatars.discourse-cdn.com/v4/letter/s/b4bc9f/32.png) [@Sky\_119](https://discourse.processing.org/u/Sky_119)\
**Post date:** [October 24, 2022, 12:46pm UTC](https://discourse.processing.org/t/how-to-make-a-game-start-menu-in-processing/6019/7 "2022-10-24T12:46:25Z")

</div>

hi, how would i make it go from the menu to the game, thanks

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [October 24, 2022, 1:21pm UTC](https://discourse.processing.org/t/how-to-make-a-game-start-menu-in-processing/6019/8 "2022-10-24T13:21:23Z")

</div>

> [@djokjula](#):
>
> `drawMenu()`

In this function you can say if(keyPressed)  
screenState = GAMESCREEN;

Or mousePressed

---

<div class="post-metadata">

**Author:** ![newuser](https://avatars.discourse-cdn.com/v4/letter/n/3e96dc/32.png) [@newuser](https://discourse.processing.org/u/newuser)\
**Post date:** [July 9, 2025, 3:56am UTC](https://discourse.processing.org/t/how-to-make-a-game-start-menu-in-processing/6019/10 "2025-07-09T03:56:48Z")

</div>

@jhonbennett_87  
Wrap your code in ``` marks before and after. The result is easier to read:

```auto
void setup() {
  // setup code
}

void draw() {
  // draw code
}

```

You should start your own topic, and leave this topic for the original poster.
