我已加載並且創建了兩個圖像按鈕menuStart和menuExit枝條menuStart.png和menuExit.png:處理 - mousePress圖像去起作用
圖像(menuStart,250,350,100,42);
image(menuExit,450,345,110,45);
我在做什麼: 我已將頁面設置爲階段。階段1是菜單,階段2是開始畫面階段3是選擇難度畫面+遊戲,階段4是退出畫面,階段5退出遊戲。我想使用mousePressed函數,這樣如果用戶在階段1中選擇menuStart按鈕,階段= 2。類似地,如果用戶在階段1中選擇menuExit按鈕,階段= 5。
我做了什麼與代碼: 我已經實現了mousePressed,但不知道如何設置mousePressed在圖像參數中的參數。我該如何着手設置?
代碼:
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();
}
}