Background(image) not working

cleaning up isnt that important to me, but what do i have to do to get it to work?

1 Like

Most issues get solved because we clean up

Do you use rectMode(CENTER) somewhere?

2 Likes

the code for

  //button unten rechts wird gedrückt

is completely missing??
and not forget the && state == 0 logic for the first 4 buttons

1 Like

You are asking for help from this community and making your code presentable is a reasonable expectation.

At the very least you could have used “Edit > Auto Format” in Processing before posting.

Go through your code.
The problem is very obvious so I will not be assisting with this.

:slight_smile:

2 Likes

sorry for not making it very presentable, but i will do this.

First, the button click checking thing works, but i doessnt at the position of the back button.

it should just check if you click it and than it shoud change to state 3.

How doesnt it do that?

1 Like

ok i will cleanup :smiley:

and no

2 Likes

that is missing, because i want to solve the problem first, i can do that later. Also, the && state == 0 doesnt matter, but i added it.

2 Likes

your logic is not working, “over” is underlined red, and it says The function … does not exist, do i have to code the function or did i do something wrong?

1 Like

You have to code the function over

It might return either true or false in the if clause

Also read your code carefully, check the sketch and the states

1 Like

how can i declare variables in functions? this doesnt work:

public void over(x, y, w, h){
  
}
1 Like

You are missing “state 4” and “checking button 4” and “draw_back_button_and_some_text4()”

I was able to cut, paste and modify and quickly get this working.

:slight_smile:

1 Like

i only need that for the button in the bottom right corner? that doesnt have anything to do with the problem or am i overlooking something

1 Like

and i still didnt get this to work: public void over(x, y, w, h){

}

1 Like

void is the return type (empty)

You don’t want that. You want boolean as return type. public is not needed.

so boolean over(…

And then just float in front of the variables

float x, float y…

2 Likes

better change it; since it can interfere

1 Like

When you read the first three textual tutorials you get a grip of functions

1 Like

Alright, i did this now, but if i press the back button, nothing happens

boolean over(float x, float y, float w, float h){
  
  if(mouseY > y && mouseY < y + h && mouseX > x && mouseY < x + w){
    
   return true; 
    
  }
  
  return false;
  
}
//zurück button wird gedrückt
  
  if ( over(80, 870, 250, 100) && state > 0) {
    
    if(mousePressed){
      
      state = 0;
      
    }
    
  }
1 Like

I also added button 4 now:

void setup() {

  size(1920, 1080);
  background(222);
}


color blue = color(3, 182, 252);
color grey = color(222);
color black = color(0);
int state = 0;



boolean over(float x, float y, float w, float h) {

  if (mouseY > y && mouseY < y + h && mouseX > x && mouseY < x + w) {

    return true;
  }

  return false;
}


public void draw_4_buttons() {

  fill(0);
  rect(100, 100, 250, 250);
  //Button oben rechts
  rect(1570, 100, 250, 250);
  //Button unten links
  rect(100, 730, 250, 250);
  //Button unten rechts
  rect(1570, 730, 250, 250);
}





void draw_back_button_and_some_text1() {

  fill(0);
  textSize(55);
  text("Hier könnte ihre Werbung stehen1", 500, 55);

  fill(blue);
  rect(80, 870, 250, 100);


  fill(0);
  textSize(55);
  text("zurück", 110, 940);
}


void draw_back_button_and_some_text2() {

  fill(0);
  textSize(55);
  text("Hier könnte ihre Werbung stehen2", 500, 55);

  fill(blue);
  rect(80, 870, 250, 100);


  fill(0);
  textSize(55);
  text("zurück", 110, 940);
}

void draw_back_button_and_some_text3() {

  fill(0);
  textSize(55);
  text("Hier könnte ihre Werbung stehen3", 500, 55);

  fill(blue);
  rect(80, 870, 250, 100);


  fill(0);
  textSize(55);
  text("zurück", 110, 940);
}



void draw_back_button_and_some_text4() {

  fill(0);
  textSize(55);
  text("Hier könnte ihre Werbung stehen4", 500, 55);

  fill(blue);
  rect(80, 870, 250, 100);


  fill(0);
  textSize(55);
  text("zurück", 110, 940);
}





void draw() {
  background(222);
  if ( state == 0 ) draw_4_buttons();
  if ( state == 1 ) draw_back_button_and_some_text1();
  if ( state == 2 ) draw_back_button_and_some_text2();
  if ( state == 3 ) draw_back_button_and_some_text3();
  if ( state == 4 ) draw_back_button_and_some_text4();



  //button oben links wird gedrückt
  if (mouseY > 100 && mouseY < 350 &&
    mouseX > 100 && mouseX < 350 ) {

    if (mousePressed && state == 0) {

      state = 1;
    }
  }


  //button oben rechts wird gedrückt
  if (mouseY > 100 && mouseY < 350 && 
    mouseX > 1570 && mouseX < 1820 ) {

    if (mousePressed && state == 0) {


      state = 2;
    }
  }

  //button unten links wird gedrückt

  if (mouseY > 730 && mouseY < 980 && 
    mouseX > 100 && mouseX < 350 ) {

    if (mousePressed && state == 0) {


      state = 3;
    }
  }

  //button unten rechts wird gedrückt

  if (mouseY > 730 && mouseY < 980 &&
    mouseX > 1570 && mouseX < 1820) {

    if (mousePressed && state == 0) {


      state = 4;
    }
  }

  //zurück button wird gedrückt

  if ( over(80, 870, 250, 100) && state > 0) {

    if (mousePressed) {

      state = 0;
    }
  }
}

1 Like

Read carefully this line

Also long lines are better readable when you make a line break after e.g. &&

1 Like

The idea is that you use over() in every line of this type.

This is the purpose of a function like over() : you can use it multiple times and it makes your code better readable and less erroneous!

Also a sketch should have following order:

  • ALL global variables etc

  • setup() and draw() in that order

  • Standard built-in functions like keyPressed, mousePressed and the like

  • Your own functions like over(). Also in hierarchiel order, the most important first, then the lesser important like over()

—————————————————

Also instead of using mousePressed as a variable in draw (), better look at the function mousePressed () in the reference and put all button checks therein.

You can distinguish both in the reference by the brackets () although they have the same name „mousePressed“. As I have written them above with and without the brackets.

Chrisir

2 Likes