Reputation: 1
I'm making a little game in Processing. But I don't know how to set the coordinates to be the same on every monitor type using fullscreen. Like in a big monitor the coordinates are different from a smaller monitor.
I tried to translate the center to the middle of the screen!
Can anyone help me?
Upvotes: 0
Views: 1288
Reputation: 42174
It sounds like you're using absolute coordinates, like this:
void setup(){
size(500, 500);
}
void draw(){
ellipse(250, 250, 400, 400);
}
This code draws a large circle in the middle of the screen. The problem is, this code does not consider the size of the window at all. So if you make it fullscreen, the circle keeps the same size and location.
Instead, you can use the width
and height
variables to make your drawing scale with the window:
void setup(){
size(500, 500);
}
void draw(){
ellipse(width / 2, height / 2, width * .8, height * .8);
}
Now the drawing will scale with the size of the window.
However, now you have a different problem: the drawing can get stretched out depending on the size of your monitor. You need to fix the aspect ratio. I'd recommend Googling that to see a ton of approaches, but for this simple example, you could just take the minimum of width
and height
and use that:
void setup() {
fullScreen();
}
void draw() {
float minDimension = min(width, height);
ellipse(width / 2, height / 2, minDimension * .8, minDimension * .8);
}
There are a ton of other ways to approach this. You could also look into using a PGraphics
that's always the same size, and then scaling that depending on the screen size.
Shameless self-promotion: here and here are tutorials on using the width
and height
variables to scale your drawings.
Upvotes: 2