I came accross a problem while making my current project. The concept would be to create a black square on a white background of 1000 by 1000 pixels, but have it be at the center of the screen. Taking into account the fact that this should work on different sizes of screens, I tried this:
int fartop=displayHeight-1000/2;
int farleft=displayWidth-1000/2;
void setup(){
size(1000,1000); //I think this doesn't matter since I put the project on full screen one line later
fullScreen();
background(255);
}
void draw(){
fill(0);
rect(farleft, fartop, 1000, 1000);
}
However, the result I got was this:
My screen size is 1920 by 1080, so logically, farleft should be equal 460 and fartop should be equal 40. But after checking the variables’ values directly, I realised they were both equal -500.
I then tried defining the variables as such to understand the problem:
int fartop=displayHeight-1000;
int farleft=displayWidth-1000;
And after this, both variables were equal -1000.
When defining the variables as just my display sizes, it gave the correct screen resolution I’m using, but as soon as I start affecting the variable, it ignores it for some reason.
I’ve also tried the following:
int fartop=displayHeight;
int farleft=displayWidth;
void setup(){
size(1000,1000);
fullScreen();
background(255);
fartop=fartop-1000/2;
farleft=farleft-1000/2;
}
But the result is the same. I have no idea what could be causing this, and I’d appreciate some insight grealy. Thank you in advance.