Background(image) not working

boolean over(float x, float y, float w, float h) { 
  if (mouseY > y && mouseY < y + h && mouseX > x && mouse**Y** < x + w) { 
    return true; 
  } 
  return false; 
}

is wrong
also start structuring your code better
and learn using variables:
try this code to get the idea:

int state = 0;

int x1=100,  y1=100, w1=250, h1=250;   //Button oben links
int x2=1570, y2=100, w2=250, h2=250;   //Button oben rechts
int x3=100,  y3=730, w3=250, h3=250;   //Button unten links
int x4=1570, y4=730, w4=250, h4=250;   //Button unten rechts

int x5=80,   y5=870, w5=250, h5=100;   // Button zurück

void draw_4_button() { //_______ stat 0 only
  if ( over(x1, y1, w1, h1) ) stroke(200,0,0); else stroke(0);
  rect(x1, y1, w1, h1);
  if ( over(x2, y2, w2, h2) ) stroke(200,0,0); else stroke(0);
  rect(x2, y2, w2, h2);
  if ( over(x3, y3, w3, h3) ) stroke(200,0,0); else stroke(0);
  rect(x3, y3, w3, h3);
  if ( over(x4, y4, w4, h4) ) stroke(200,0,0); else stroke(0);
  rect(x4, y4, w4, h4);
}

void draw_zurueck_button() { //_ state 1,2,3
  if ( over(x5, y5, w5, h5) ) stroke(200,0,0); else stroke(0);
  rect(x5, y5, w5, h5);
}

void setup() {
  size(1920, 1080);
  fill(0,0,200);
  strokeWeight(10);
}

void draw() {
  background(200,100,200);
  if ( state == 0 ) draw_4_buttons();
  if ( state > 0 ) draw_back_button_and_some_text(state);
}

void draw_4_buttons() {
  draw_4_button();
}

void draw_back_button_and_some_text(int page ) {
  text("some text page "+page,20,20);
  draw_zurueck_button();
}

boolean over(int x, int y, int w, int h) {
  return ( mouseX > x & mouseX < x + w   &&
    mouseY > y & mouseY < y + h      ) ;
}

1 Like

what is that for? and i am trying it out now

1 Like

oh i see :smiley: why did i not see that?

1 Like

i have written the clicking part know, and i still cant press the bottom part/half of the 3. button.

int state = 0;

int x1=100, y1=100, w1=250, h1=250;   //Button oben links
int x2=1570, y2=100, w2=250, h2=250;   //Button oben rechts
int x3=100, y3=730, w3=250, h3=250;   //Button unten links
int x4=1570, y4=730, w4=250, h4=250;   //Button unten rechts

int x5=80, y5=870, w5=250, h5=100;   // Button zurück

void draw_4_button() { //_______ stat 0 only
  if ( over(x1, y1, w1, h1) ) stroke(200, 0, 0); 
  else stroke(0);
  rect(x1, y1, w1, h1);
  if ( over(x2, y2, w2, h2) ) stroke(200, 0, 0); 
  else stroke(0);
  rect(x2, y2, w2, h2);
  if ( over(x3, y3, w3, h3) ) stroke(200, 0, 0); 
  else stroke(0);
  rect(x3, y3, w3, h3);
  if ( over(x4, y4, w4, h4) ) stroke(200, 0, 0); 
  else stroke(0);
  rect(x4, y4, w4, h4);
}

void draw_zurueck_button() { //_ state 1,2,3
  if ( over(x5, y5, w5, h5) ) stroke(200, 0, 0); 
  else stroke(0);
  rect(x5, y5, w5, h5);
}

void setup() {
  size(1920, 1080);
  fill(0, 0, 200);
  strokeWeight(10);
}

void draw() {
  background(200, 100, 200);
  if ( state == 0 ) draw_4_buttons();
  if ( state > 0 ) draw_back_button_and_some_text(state);
}

void mousePressed() {

  if ( over(x1, y1, w1, h1) ) {

    state = 1;
  }

  if ( over(x2, y2, w2, h2) ) {

    state = 2;
  }

  if ( over(x3, y3, w3, h3) ) {

    state = 3;
  }

  if ( over(x4, y4, w4, h4) ) {

    state = 4;
  }

  if ( over(x5, y5, w5, h5) ) {

    state = 0;
  }
}

void draw_4_buttons() {
  draw_4_button();
}

void draw_back_button_and_some_text(int page ) {
  text("some text page "+page, 20, 20);
  draw_zurueck_button();
}

boolean over(int x, int y, int w, int h) {
  return ( mouseX > x & mouseX < x + w   &&
    mouseY > y & mouseY < y + h      ) ;
}

1 Like

where is your code?

if ( over() && state == x )  state = y;

you NEEED as button 3 and 5 overlap

you can easy avoid if you move the zurueck button in the middle

1 Like

Its this part:

void mousePressed() {

  if ( over(x1, y1, w1, h1) && state == 0) {

    state = 1;
  }

  if ( over(x2, y2, w2, h2) && state == 0) {

    state = 2;
  }

  if ( over(x3, y3, w3, h3) && state == 0) {

    state = 3;
  }

  if ( over(x4, y4, w4, h4) && state == 0) {

    state = 4;
  }

  if ( over(x5, y5, w5, h5) && state != 0) {

    state = 0;
  }
}
1 Like

look at the code i posted below

void mousePressed() {

  if ( over(x1, y1, w1, h1) && state == 0) {

    state = 1;
  }

  if ( over(x2, y2, w2, h2) && state == 0) {

    state = 2;
  }

  if ( over(x3, y3, w3, h3) && state == 0) {

    state = 3;
  }

  if ( over(x4, y4, w4, h4) && state == 0) {

    state = 4;
  }

  if ( over(x5, y5, w5, h5) && state != 0) {

    state = 0;
  }
}
1 Like

He suffered enough

Somebody do it for him please

1 Like

void mousePressed() {
    
    switch (state) {
    
    case 0:
        if.....
        if.....
        //.....
        break;
        
    case 1:
        //....
        break;
    
    }
}
2 Likes

but i have written the if over things, what do i do wrong?

1 Like

In the form you have now better use if… else if… OR return; every time after state=x;

1 Like
void mousePressed() {
  if ( state == 0 ) {
    if ( over(x1, y1, w1, h1) )  state = 1;
    if ( over(x2, y2, w2, h2) )  state = 2;
    if ( over(x3, y3, w3, h3) )  state = 3;
    if ( over(x4, y4, w4, h4) )  state = 4;
  } else {
    if ( over(x5, y5, w5, h5) )  state = 0;
  }
}

should work same as the switch???

1 Like

You change state within the function. But then the button gets check on the new state. That’s bad. Therefore you get a double hit on buttons. Use return OR else if

Did you fix over ?

Post your entire code please

1 Like

This code section looks good now.

You could achieve this with switch but no need.

Does it work now?

Did you fix over() function?

1 Like

yes, no bounce back here

1 Like

it does, i dont know how, because i did the same thing yesterday and it didnt

2 Likes

Well… you had an error in over() and you had a missing else if construct

I think that’s it

1 Like

Thank you for your help everything is working fine
@Chrisir
@kll

2 Likes

Guess this can still go wrong because of missing else if within the main if

Not in this code but:
when x1 and x3 overlap both buttons would be executed

1 Like

To close this discussion:

Can you please post your entire code?

2 Likes