Adding a Start Screen to my drawing program

Can someone let me know how it’s possible to add this to my code, for example, I want to add a start game button in this code and this screen should pop up every time I start a canvas and to enter the program I would need to press a Start gameplay button. Thanks for any possible help.

int startTimeMs;
// The time until the game starts, in milliseconds
// (easy to convert to seconds, sec = ms/1000)
final int startDelayMs = 5000;
boolean atStartup = true;
 
int gameWidth = 600;
int gameHeight = 300;
 
void setup(){
  size(600, 300);
  // Current time, in milliseconds
  startTimeMs = millis();
}
 
void draw(){
  // If we're in the startup time window, show a countdown
  if (atStartup) {
    // The current time, in milliseconds
    int curTimeMs = millis();
    // The remaining time in the startup period
    int startupTimeRemainingMs = startDelayMs - (curTimeMs - startTimeMs);
    startScreen(startupTimeRemainingMs);
    atStartup = startupTimeRemainingMs > 0;
    // Short-circuit if we're still in the startup phase.
    return;
  }
  background(240);
  fill(0);
  textAlign(CENTER,CENTER);
  text("Welcome to DrawSpace!", gameWidth/2, gameHeight/2);
}
 
void startScreen(int remainingTimeMs){
  background(50);
  textSize(50);
  fill(0);
  textAlign(CENTER,CENTER);
  // Show the remaining time, in seconds;
  // show n when there are n or fewer seconds remaining. 
  text(ceil(remainingTimeMs/1000.0), gameWidth/2, gameHeight/2);
}

Yes it’s possible

Chrisir

How would I be able to do that?

Thanks,

copy the parts you need from above into your Sketch

you need this and the sections where atStartup occurs

set atStartup = true; when you want to go to the start screen

say atStartup = false; to leave the start screen and enter the Drawing Part of your Sketch

you know how to make buttons. Make a Start gameplay button; then display it in the atStartup == true section in draw(). When the button is pressed, say atStartup = false;

mousePressed

Therefore in mousePressed() say similar to the code in draw() :

void mousePressed() {
    if(atStartup) {
        //if mouse inside button, but not necessary
        atStartup=false; 
        return; // leave 
    }// if

    // WHAT you have in mousePressed() now

}//func 

Chrisir

Alright, Thank You So Much!!!

1 Like