klap
1
Objects doesn’t adapt to fullscreen size. A tiny ball in on a large screen. What do I miss here?
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;
}
}
}
1 Like
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,
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
1 Like
klap
3
Thanks. Looks like that gives me problems with local vs global variables.
…cannot be resolved to be a variable
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;
}
}
}
debxyz
4
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:
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().

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