# Fullscreen, what do I miss here?

**URL:** <https://discourse.processing.org/t/fullscreen-what-do-i-miss-here/21917>\
**Category:** Coding Questions\
**Created:** [June 16, 2020, 12:42pm UTC](https://discourse.processing.org/t/fullscreen-what-do-i-miss-here/21917 "2020-06-16T12:42:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![klap](https://avatars.discourse-cdn.com/v4/letter/k/a698b9/32.png) [@klap](https://discourse.processing.org/u/klap)\
**Post date:** [June 16, 2020, 12:42pm UTC](https://discourse.processing.org/t/fullscreen-what-do-i-miss-here/21917/1 "2020-06-16T12:42:36Z")

</div>

Objects doesn’t adapt to fullscreen size. A tiny ball in on a large screen. What do I miss here?

```auto
float ellipseX = (width / 2);
float ellipseY = (height / 10);
int rectX = ((width / 2) - 10);
int rectY = (height - 10);
float ballMoveHor = 0;
float ballMoveVer = 0;
int distance = 15;
int lives = 3;
int points = 0;
int highscore = 0;
int ellipseH = height/10;
int ellipseB = width/10;
int rectW = width/5;
int rectH = height/12;
color ellipseColor1 = color(234, 255, 10);
color rectColor1 = color(0);
//color rectColor2 = color(255);
boolean pauSe = false;

void setup() {
  //surface.setResizable(true); 
  fullScreen();
}

void draw() {
  background(55, 155, 5);

  //After 3 errors, 'lives' = 0 -> Game Over!

  if (lives == 0) {
    println("GAME OVER!");
    println("Your score: ");
    println(points);
    if (points > highscore) { //Highscore?
      highscore = points;
      println("New Highscore!");
    } else {
      delay(2000);
      println("You failed!!!");
      delay(3000);
      println("But wait...");
      delay(2000);
    }
    println("The Processing Prince gives you 3 new lives for free"); //three more lives!
    //println(lives);
    delay(2000); 
    println("Press SPACE to continue.");
    lives = 3;
    points = 0;
  }

  if (keyPressed == true) { //press space to (re)start the game
    if ((key == ' ' ) && (ballMoveVer == 0)) {
      loop();
      pauSe = false;
      ballMoveVer = random(1, 2);
      ballMoveHor = random(1, 2);
    } else if ((keyCode == RIGHT) && (key == ' ')) { //sliding
      rectX += 2;
    } else if (keyCode == RIGHT) { //move right
      rectX++;
    } else if (keyCode == LEFT) { //move left
      rectX--;
    }
  }

  fill(ellipseColor1);
  ellipse(ellipseX, ellipseY, ellipseH, ellipseB); //draw the ball

  //bal moves horizontal

  if (ellipseX > width) { //make ball bounce from sidewalls
    ballMoveHor = random(-1, -3);
  } else if (ellipseX < 0) {
    ballMoveHor = random(1, 2.5);
  }
  ellipseX += ballMoveHor;

  //ball moves vertical

  if (ellipseY+5 > height) { //ball touches ground!
    ellipseY = 10;
    ellipseX = width/2;
    ballMoveVer = 0;
    ballMoveHor = 0;
    lives--;
    println("lives: ");
    println(lives);
    //noLoop();
  } else if (ellipseY < 0) {
    ballMoveVer = random(1, 2.5);
  }
  ellipseY += ballMoveVer;

  //rectColor1 = color(0);
  fill(rectColor1);
  rect(rectX, rectY, rectW, rectH); //draw rectangle to catch ball

  if (rectX >= (width-20)) { //add boundaries for rectangle
    rectX = (width-20);
  } else if (rectX <= -10) {
    rectX = -10;
  }

  //distance check

  float dist2 = dist(rectX+15, height+5, ellipseX, ellipseY+5);
  //float dist3 = dist(rectX, rectY, x, y);

  if (dist2 < distance) {
    rectColor1 = color(255); //change rect color to white
    ellipseY -=4;
    ballMoveHor = random(1, 2);
    ballMoveVer = random(-1, -2);
    points++;
    println("points: "); 
    println(points);
  } else {
    rectColor1 = color(0); //let white color flash back to black
  }
}

void keyPressed() {
  if ((key == 'p') && (ballMoveVer != 0)) {
    if (pauSe == false) {
      pauSe = true;
      noLoop();
    } else {
      pauSe = false;
      loop();
    }
    println(pauSe);

    if (key == ENTER) {
      loop();
      pauSe = false;
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![MiguelSanches](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/miguelsanches/32/11172_2.png) [@MiguelSanches](https://discourse.processing.org/u/MiguelSanches)\
**Post date:** [June 16, 2020, 12:59pm UTC](https://discourse.processing.org/t/fullscreen-what-do-i-miss-here/21917/2 "2020-06-16T12:59:38Z")

</div>

Hi @klap,

Welcome to the community! 🙂

Try, defining the variable values dependent on the size of the window after you declare the size of it.  
So,

```auto
  ellipseX = (width / 2);
  ellipseY = (height / 10);
  rectX = ((width / 2) - 10);
  rectY = (height - 10);
  
  ellipseH = height/10;
  ellipseB = width/10;
  rectW = width/5;
  rectH = height/12;

```

should be inside setup and after fullScreen.

As an exercise, try printing the ellipseX value before the fullScreen statement, and after declaring it again inside setup and see the difference 😉

Best regards

---

<div class="post-metadata">

**Author:** ![klap](https://avatars.discourse-cdn.com/v4/letter/k/a698b9/32.png) [@klap](https://discourse.processing.org/u/klap)\
**Post date:** [June 16, 2020, 1:06pm UTC](https://discourse.processing.org/t/fullscreen-what-do-i-miss-here/21917/3 "2020-06-16T13:06:34Z")

</div>

Thanks. Looks like that gives me problems with local vs global variables.

…cannot be resolved to be a variable

```auto

float ballMoveHor = 0;
float ballMoveVer = 0;
int distance = 15;
int lives = 3;
int points = 0;
int highscore = 0;

color ellipseColor1 = color(234, 255, 10);
color rectColor1 = color(0);
//color rectColor2 = color(255);
boolean pauSe = false;

void setup() {
  //surface.setResizable(true); 
  fullScreen();
  float ellipseX = (width / 2);
float ellipseY = (height / 10);
int rectX = (width / 2 - 10);
int rectY = (height - 10);
int ellipseH = height/10;
int ellipseB = width/10;
int rectW = width/5;
int rectH = height/12;

}

void draw() {

  background(55, 155, 5);

  //After 3 errors, 'lives' = 0 -> Game Over!

  if (lives == 0) {
    println("GAME OVER!");
    println("Your score: ");
    println(points);
    if (points > highscore) { //Highscore?
      highscore = points;
      println("New Highscore!");
    } else {
      delay(2000);
      println("You failed!!!");
      delay(3000);
      println("But wait...");
      delay(2000);
    }
    println("The Processing Prince gives you 3 new lives for free"); //three more lives!
    //println(lives);
    delay(2000); 
    println("Press SPACE to continue.");
    lives = 3;
    points = 0;
  }

  if (keyPressed == true) { //press space to (re)start the game
    if ((key == ' ' ) && (ballMoveVer == 0)) {
      loop();
      pauSe = false;
      ballMoveVer = random(1, 2);
      ballMoveHor = random(1, 2);
    } else if ((keyCode == RIGHT) && (key == ' ')) { //sliding
      rectX += 2;
    } else if (keyCode == RIGHT) { //move right
      rectX++;
    } else if (keyCode == LEFT) { //move left
      rectX--;
    }
  }

  fill(ellipseColor1);
  ellipse(ellipseX, ellipseY, ellipseH, ellipseB); //draw the ball

  //bal moves horizontal

  if (ellipseX > width) { //make ball bounce from sidewalls
    ballMoveHor = random(-1, -3);
  } else if (ellipseX < 0) {
    ballMoveHor = random(1, 2.5);
  }
  ellipseX += ballMoveHor;

  //ball moves vertical

  if (ellipseY+5 > height) { //ball touches ground!
    ellipseY = 10;
    ellipseX = width/2;
    ballMoveVer = 0;
    ballMoveHor = 0;
    lives--;
    println("lives: ");
    println(lives);
    //noLoop();
  } else if (ellipseY < 0) {
    ballMoveVer = random(1, 2.5);
  }
  ellipseY += ballMoveVer;

  //rectColor1 = color(0);
  fill(rectColor1);
  rect(rectX, rectY, rectW, rectH); //draw rectangle to catch ball

  if (rectX >= (width-20)) { //add boundaries for rectangle
    rectX = (width-20);
  } else if (rectX <= -10) {
    rectX = -10;
  }

  //distance check

  float dist2 = dist(rectX+15, height+5, ellipseX, ellipseY+5);
  //float dist3 = dist(rectX, rectY, x, y);

  if (dist2 < distance) {

    rectColor1 = color(255); //change rect color to white
    ellipseY -=4;
    ballMoveHor = random(1, 2);
    ballMoveVer = random(-1, -2);
    points++;
    println("points: "); 
    println(points);
  } else {
    rectColor1 = color(0); //let white color flash back to black
  }
}

void keyPressed() {
  if ((key == 'p') && (ballMoveVer != 0)) {
    if (pauSe == false) {
      pauSe = true;
      noLoop();
    } else {
      pauSe = false;
      loop();
    }
    println(pauSe);

    if (key == ENTER) {
      loop();
      pauSe = false;
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![debxyz](https://avatars.discourse-cdn.com/v4/letter/d/58956e/32.png) [@debxyz](https://discourse.processing.org/u/debxyz)\
**Post date:** [June 16, 2020, 1:16pm UTC](https://discourse.processing.org/t/fullscreen-what-do-i-miss-here/21917/4 "2020-06-16T13:16:16Z")

</div>

Hello @klap,  
Declare the variables at top of your sketch, and then initialize them in setup below line fullscreen().  
I just tested and this works.

For example starting with your first global variable, it would look like this to decalre:

> [@klap](#):
>
> ```auto
> float ellipseX;
> 
> ```

And then next line beneath fullscreen() you initialize and it looks like this:

`ellipseX = width/2;`

Basically what @MiguelSanches said…

And the lesson here being, **you cannot use width and height to initialize a variable before setup().**  
🤓

---

<div class="post-metadata">

**Author:** ![klap](https://avatars.discourse-cdn.com/v4/letter/k/a698b9/32.png) [@klap](https://discourse.processing.org/u/klap)\
**Post date:** [June 16, 2020, 1:19pm UTC](https://discourse.processing.org/t/fullscreen-what-do-i-miss-here/21917/5 "2020-06-16T13:19:21Z")

</div>

Ok, I tried that as well, but without ‘int, float etc’ in front of it it works. I see. thanks
