# Background(image) not working

**URL:** https://discourse.processing.org/t/background-image-not-working/14305
**Category:** Coding Questions
**Created:** [September 30, 2019, 6:32am UTC](https://discourse.processing.org/t/background-image-not-working/14305 "2019-09-30T06:32:27Z")
**Posts on this page:** 20
**Page:** 2

<div class="post-metadata">

### Author: ![Ladan](https://avatars.discourse-cdn.com/v4/letter/l/dbc845/32.png) [@Ladan](https://discourse.processing.org/u/Ladan)
#### Post date: [November 10, 2019, 1:45pm UTC](https://discourse.processing.org/t/background-image-not-working/14305/21 "2019-11-10T13:45:00Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [November 10, 2019, 1:48pm UTC](https://discourse.processing.org/t/background-image-not-working/14305/22 "2019-11-10T13:48:44Z")

</div>

Most issues get solved because we clean up

Do you use rectMode(CENTER) somewhere?

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [November 10, 2019, 1:51pm UTC](https://discourse.processing.org/t/background-image-not-working/14305/23 "2019-11-10T13:51:36Z")

</div>

the code for

```auto
  //button unten rechts wird gedrückt

```

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

---

<div class="post-metadata">

### Author: ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)
#### Post date: [November 10, 2019, 2:03pm UTC](https://discourse.processing.org/t/background-image-not-working/14305/24 "2019-11-10T14:03:24Z")

</div>

> [@Ladan](#):
>
> cleaning up isnt that important to me

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.

> [@Ladan](#):
>
> but what do i have to do to get it to work?

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

🙂

---

<div class="post-metadata">

### Author: ![Ladan](https://avatars.discourse-cdn.com/v4/letter/l/dbc845/32.png) [@Ladan](https://discourse.processing.org/u/Ladan)
#### Post date: [November 10, 2019, 2:42pm UTC](https://discourse.processing.org/t/background-image-not-working/14305/25 "2019-11-10T14:42:37Z")

</div>

> [@glv](#):
>
> At the very least you could have used “Edit \> Auto Format” in Processing before posting.

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?

---

<div class="post-metadata">

### Author: ![Ladan](https://avatars.discourse-cdn.com/v4/letter/l/dbc845/32.png) [@Ladan](https://discourse.processing.org/u/Ladan)
#### Post date: [November 10, 2019, 2:43pm UTC](https://discourse.processing.org/t/background-image-not-working/14305/26 "2019-11-10T14:43:11Z")

</div>

ok i will cleanup 😃

and no

---

<div class="post-metadata">

### Author: ![Ladan](https://avatars.discourse-cdn.com/v4/letter/l/dbc845/32.png) [@Ladan](https://discourse.processing.org/u/Ladan)
#### Post date: [November 10, 2019, 2:45pm UTC](https://discourse.processing.org/t/background-image-not-working/14305/27 "2019-11-10T14:45:09Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Ladan](https://avatars.discourse-cdn.com/v4/letter/l/dbc845/32.png) [@Ladan](https://discourse.processing.org/u/Ladan)
#### Post date: [November 10, 2019, 2:51pm UTC](https://discourse.processing.org/t/background-image-not-working/14305/28 "2019-11-10T14:51:39Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [November 10, 2019, 2:52pm UTC](https://discourse.processing.org/t/background-image-not-working/14305/29 "2019-11-10T14:52:52Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Ladan](https://avatars.discourse-cdn.com/v4/letter/l/dbc845/32.png) [@Ladan](https://discourse.processing.org/u/Ladan)
#### Post date: [November 10, 2019, 2:55pm UTC](https://discourse.processing.org/t/background-image-not-working/14305/30 "2019-11-10T14:55:54Z")

</div>

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

```auto
public void over(x, y, w, h){
  
}

```

---

<div class="post-metadata">

### Author: ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)
#### Post date: [November 10, 2019, 3:19pm UTC](https://discourse.processing.org/t/background-image-not-working/14305/31 "2019-11-10T15:19:45Z")

</div>

> [@Ladan](#):
>
> If i click the bottom half of the button on the bottom left corner, nothing happens.

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.

🙂

---

<div class="post-metadata">

### Author: ![Ladan](https://avatars.discourse-cdn.com/v4/letter/l/dbc845/32.png) [@Ladan](https://discourse.processing.org/u/Ladan)
#### Post date: [November 10, 2019, 4:13pm UTC](https://discourse.processing.org/t/background-image-not-working/14305/32 "2019-11-10T16:13:10Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Ladan](https://avatars.discourse-cdn.com/v4/letter/l/dbc845/32.png) [@Ladan](https://discourse.processing.org/u/Ladan)
#### Post date: [November 10, 2019, 4:13pm UTC](https://discourse.processing.org/t/background-image-not-working/14305/33 "2019-11-10T16:13:59Z")

</div>

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

}

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [November 10, 2019, 6:22pm UTC](https://discourse.processing.org/t/background-image-not-working/14305/34 "2019-11-10T18:22:14Z")

</div>

> [@Ladan](#):
>
> public void over(x, y, w, h){ }

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…

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [November 10, 2019, 6:23pm UTC](https://discourse.processing.org/t/background-image-not-working/14305/35 "2019-11-10T18:23:32Z")

</div>

> [@Ladan](#):
>
> that doesnt have anything to do with the problem or am i overlooking something

better change it; since it can interfere

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [November 10, 2019, 6:24pm UTC](https://discourse.processing.org/t/background-image-not-working/14305/36 "2019-11-10T18:24:13Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Ladan](https://avatars.discourse-cdn.com/v4/letter/l/dbc845/32.png) [@Ladan](https://discourse.processing.org/u/Ladan)
#### Post date: [November 10, 2019, 7:23pm UTC](https://discourse.processing.org/t/background-image-not-working/14305/37 "2019-11-10T19:23:50Z")

</div>

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

```auto
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;
  
}

```

```auto
//zurück button wird gedrückt
  
  if ( over(80, 870, 250, 100) && state > 0) {
    
    if(mousePressed){
      
      state = 0;
      
    }
    
  }

```

---

<div class="post-metadata">

### Author: ![Ladan](https://avatars.discourse-cdn.com/v4/letter/l/dbc845/32.png) [@Ladan](https://discourse.processing.org/u/Ladan)
#### Post date: [November 10, 2019, 7:34pm UTC](https://discourse.processing.org/t/background-image-not-working/14305/38 "2019-11-10T19:34:04Z")

</div>

I also added button 4 now:

```auto
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;
    }
  }
}

```

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [November 10, 2019, 9:34pm UTC](https://discourse.processing.org/t/background-image-not-working/14305/39 "2019-11-10T21:34:24Z")

</div>

> [@Ladan](#):
>
> mouseX \> x && mouseY \< x + w) {

Read carefully this line

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

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [November 10, 2019, 9:44pm UTC](https://discourse.processing.org/t/background-image-not-working/14305/40 "2019-11-10T21:44:20Z")

</div>

> [@Ladan](#):
>
> if (mouseY \> 730 && mouseY \< 980 && mouseX \> 1570 && mouseX \< 1820) {

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

[Previous page](https://discourse.processing.org/t/background-image-not-working/14305.md?page=1)

[Next page](https://discourse.processing.org/t/background-image-not-working/14305.md?page=3)
