Using booleans to switch scenes. Help please! =)
in
Programming Questions
•
6 months ago
Hello all!
So for a project, We need to make an interactive "kiosk" for a museum. Right now, I'm trying to make "dummy" code to reference to throughout my project.
I'm trying to use booleans to change "scenes" in the kiosk. (example: Start at an opening menu, click a button then go to a page for an exhibit) and so I'd be turning each scene on and off depending on how the user navigates.
For my dummy, I want to be able to click the rectangle and then go to a new scene with a white background.
Any help is greatly appreciated!!!
int ButtonX, ButtonY;
int ButtonSize = 50;
color ButtonColor, ButtonHL;
boolean ButtonOver = false;
boolean newScene = false;
//boolean Scene2 = false;
void setup(){
size(displayWidth,displayHeight);
ButtonColor = color(150);
ButtonHL = color(255);
ButtonX = width/2;
ButtonY = height/2;
rectMode(CENTER);
}
void draw(){
update(mouseX,mouseY);
if(newScene){
drawNewScene();
}
if(ButtonOver){
fill(ButtonHL);
}
else
{
fill(ButtonColor);
}
stroke(0);
rect(ButtonX, ButtonY, ButtonSize, ButtonSize);
}
void update(int x, int y) {
if(newScene){
if (ButtonOver(ButtonX, ButtonY, ButtonSize, ButtonSize)) {
ButtonOver= true;
}else{
ButtonOver = false;
}
newScene = false;
}
}
boolean ButtonOver(int x, int y, int width, int height){
if (mousePressed && mouseX >= x && mouseX <= x +width &&
mouseY >= y && mouseY <= y +height){
return true;
}
else{
return false;
}
}
void drawNewScene (){
background(255);
ellipse(width/2,height/2,400,400);
}
void mousePressed(){
update (mouseX,mouseY);
if(ButtonOver){
// ButtonColor = ButtonHL;
newScene = true;
}
}
1