# Menu Screen Help

**URL:** <https://discourse.processing.org/t/menu-screen-help/10766>\
**Category:** Coding Questions\
**Created:** [April 29, 2019, 10:43pm UTC](https://discourse.processing.org/t/menu-screen-help/10766 "2019-04-29T22:43:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![luooke](https://avatars.discourse-cdn.com/v4/letter/l/b9bd4f/32.png) [@luooke](https://discourse.processing.org/u/luooke)\
**Post date:** [April 29, 2019, 10:43pm UTC](https://discourse.processing.org/t/menu-screen-help/10766/1 "2019-04-29T22:43:59Z")

</div>

I’m having trouble with my menu screen for a game I’m trying to code. When I click the mouse, it isn’t taking me to the next screen (i.e when I click levels it doesn’t show the levels screen.) Can anyone help me? Thank you! (Here’s what I have for the code so far)

```auto
int select=1;//start game-1,levels-2,instructions-3

int gameScreen=1;//game-1,levels-2,instructions-3,main menu-4

void setup(){

fullScreen();

}

void draw(){

  textSize(80);

 println(mouseX,mouseY);

 click();

 titles();

}

void titles(){

  background(0);

 text("START GAME",50,250); 

 text("LEVELS",50,550);

 text("HOW TO PLAY",50,850); 

}

void gamePlay(){//MOVE TO NEW TAB WHEN STARTING FOR ALL VOIDS

 background(0);

 text("Start game here", 50,550);

}

void levels(){

  background(0);

  textSize(80);

 text("LEVEL 1",850,150);

 text("LEVEL 2",850,350);

 text("LEVEL 3",850,550);

 text("LEVEL 4",850,750);

 text("LEVEL 5",850,950);

}

void tutorial(){

  text("We will write the tutorial here",50,550);

}

void click(){

  

 if (mouseX>34 && mouseX<563 && mouseY>174 && mouseY<255 && mousePressed){

  gameScreen=1;//game

 }

 if (mouseX>34 && mouseX<328 && mouseY>483 && mouseY<551 && mousePressed){

 gameScreen=2;//levels

 } 

 if (mouseX>34 && mouseX<333 && mouseY>770 && mouseY<858 && mousePressed){

  gameScreen=3;//instructions

 }

}

```

---

<div class="post-metadata">

**Author:** ![hotfooted](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/hotfooted/32/3670_2.png) [@hotfooted](https://discourse.processing.org/u/hotfooted)\
**Post date:** [April 30, 2019, 1:13am UTC](https://discourse.processing.org/t/menu-screen-help/10766/2 "2019-04-30T01:13:06Z")

</div>

it might be to your benefit to build a button class. here is a simple example.

```auto
class Button
{
  float x, y, w, h, padding;
  String label;
  Button(float x, float y, String label) {
    this.padding = 10;
    this.w = textWidth(label) + padding;
    this.h = textAscent() + textDescent() + padding;
    this.x = x - this.w / 2;
    this.y = y - this.h / 2;
    this.label = label;
  }
  
  boolean hitTest(float x, float y) {
    return (this.x < x && this.x + this.w > x &&
            this.y < y && this.y + this.h > y);
  }
  
  void present() {
    fill(100, 0, 100);
    rect(this.x, this.y, this.w, this.h);
    fill(255);
    text(this.label, this.x + this.padding / 2, this.y + textAscent() + this.padding / 2);
  }
}

int state;
Button[] buttons;

void setup() {
  size(640, 480, P2D);
  state = 0;
  buttons = new Button[] {
    new Button(width / 2, height / 2, "New Game") 
  };
}

void mousePressed() {
  for(Button b : buttons) {
    if(b.hitTest(mouseX, mouseY)) {
      switch(b.label) {
        case "New Game":
          state = 1;
          break;
      }
    }
  }
}

void draw() {
  background(0);
  for(Button b : buttons) {
    b.present();
  }
  text(state, 10, 10);
}

```

---

<div class="post-metadata">

**Author:** ![luooke](https://avatars.discourse-cdn.com/v4/letter/l/b9bd4f/32.png) [@luooke](https://discourse.processing.org/u/luooke)\
**Post date:** [April 30, 2019, 1:36am UTC](https://discourse.processing.org/t/menu-screen-help/10766/3 "2019-04-30T01:36:09Z")

</div>

I got it to work finally 🙂 Thank you so much!!!
