How to make button change background in order?
in
Programming Questions
•
28 days ago
Hello,
I have to problems that I need some help to solve, I've only been programming for 1½ day so please bare over with me :)
1st question:
I need some help as how to make backgrounds change in order, like if I want my first button to make it go from yellow, to green, to red and then go back to the first one again (which would be yellow).
2nd question:
I would also like some help as to how I make make it like "steps" like if I pressed the right button it will go to red, then blue (like the 1st question) but if you press the left button the I would like it to go back to the last color.
If I press the right button twice I end up with a blue background but if I then press the left button I want it to go backwards (which will make me go back to red).
Here is what I've made so far:
int width = 188;
int height = 184;
void setup() {
size(600,400);
background(255);
}
void draw() {
image(loadImage("black_arrow_left.gif"),100,100);
if (mouseX >= 100 && mouseX <= 100 + width &&
mouseY >= 100 && mouseY <= 100 + height )
{
image(loadImage("blue_arrow_left.gif"),100,100);
}
image(loadImage("black_arrow_right.gif"),300,100);
if (mouseX >= 300 && mouseX <= 300 + width &&
mouseY >= 100 && mouseY <= 100 + height )
{
image(loadImage("blue_arrow_right.gif"),300,100);
}
}
void mousePressed() {
if (mouseX >= 100 && mouseX <= 100 + width &&
mouseY >= 100 && mouseY <= 100 + height )
{
background(203,8,151);
}
if (mouseX >= 300 && mouseX <= 300 + width &&
mouseY >= 100 && mouseY <= 100 + height )
{
background(184,8,203);
}
}
1