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);
}