I have loaded and created two image buttons menuStart and menuExit withe menuStart.png and menuExit.png:
image(menuStart, 250, 350, 100, 42);
image(menuExit, 450, 345, 110, 45);
What I've doing: I have set my pages as stages. stage 1 is a menu, stage 2 is a start screen stage 3 is a select difficulty screen + game, stage 4 is an exit screen, and stage 5 exits a game. I want to use the function mousePressed so that if the user selects the menuStart button in stage 1, stage = 2. Similarly if the user selects the menuExit button in stage 1, stage = 5.
What I've done with code: I have implemented the mousePressed but do not know how to set parameters for mousePressed in an image parameter. How do I go about setting this up?
code:
void doMenu() {
// Stage 1 Start -- MENU
if (stage == 1) {
textFont(title);
text("Game", 150, 200);
textFont(subtitle);
image(menuStart, 250, 350, 100, 42);
image(menuExit, 450, 345, 110, 45);
mousePressed();
if(mousePressed == true) {
stage = 2;
}
}
// Stage 2 START
if (stage == 2) {
background(255);
startScreen = loadImage("start.png");
image(startScreen, 0, 0, 800, 500);
if(mousePressed == true) { // true -->start
stage = 3; // go-to stage 3
}
/* else if(mousePressed == exit && stage != 2 { // exit
stage = 5; // go-to exit
}
*/
}
if(stage == 3) {
background(255);
startScreen = loadImage("start.png");
image(startScreen, 0, 0, 800, 500);
text("Press N for Normal or H for Hard", 200, 375);
if(mousePressed == true) { // true --> hard
hard = true;
normal = false;
startMenu = false;
}
/*
else if(mousePressed == normal) { // normal
hard = false;
normal = true;
startMenu = false;
}
*/
/*
if(mousePressed == true) { // easy
hard = false;
normal = true;
startMenu = false;
}
*/
}
// Stage 4 EXIT
if (stage == 4) {
background(0);
exitScreen = loadImage("exit.jpg");
image(exitScreen, 0, 0, 800, 400);
textFont(subtitle);
text("Press X to Exit", 300, 375);
if(mousePressed == true) {
stage = 5;
}
}
if(stage == 5) {
exit();
}
}