1

I am using Processing to create a basketball game. I have managed to create the basketball game but I want to have a click to start home screen. I have made the graphic for the home screen but I am not sure how to integrate it into the game code. Any ideas on how to go about this. Thanks!

I found something on the internet related to this which was...

if (started) {
   //all the code for the game
} else {
  // all the code for the start screen
 if (keyDown("enter")) {
   started = true;
 }
}

Im not sure if this is leading me in the right direction or how I could necessarily use this.

2 Answers2

0

Use keyPressed() outside the draw().

void keyPressed() {
  println(int(key));
  if (key==10) {
    println("ENTER");
  }
}

key - contains the value of the most recent key on the keyboard that was used (either pressed or released).
What is described in: https://processing.org/reference/keyPressed_.html

Mruk
  • 171
  • 1
  • 11
0

Here is a little demo program that may help you. The global variable started controls whether the game has begun or not. The function keyPressed sets it to true if you press the ENTER key.

In draw, put your game code in the first if-part and your waiting screen in the second.

boolean started = false;

void draw() {
  background(0);
  textAlign(CENTER);
  if (started) {
    // your game code here
    text("gameplay", 50, 50);
  } else {
    // your start/launch screen here
    text("waiting...", 50, 50);
  }
}

void keyPressed() {
  if (keyCode == ENTER) {
    started = true;
  }
}