Java 2D Pixel Game Tutorial - Episode 2 - Getting The Screen Size

preview_player
Показать описание
In this episode we obtain the size of the user's screen so that our game will be correctly sized. If you have any questions or comments, leave them below!
Рекомендации по теме
Комментарии
Автор

nice one man! im still not sure if that loop was necessary but hey as long as it works im ok with it ^^

PoWR
Автор

Im on a windows and when i try to run it as a java application it gives an error

APPA-Agario-nqxn
Автор

That mathematical operation is unnecessary:
 gameWidth = canvasWidth / factor * xDiff / factor;
 gameHeight = canvasHeight / factor * yDiff / factor;
To set the width and height of the frame to the width and height of the screen, respectively, use:
 gameWidth = screenSize.width;
 gameHeight = screenSize.height;

genius
Автор

The while loop seems unnecessary, take the floored quotient of the screen dimensions and choose which ever is smaller as the aspect ratio, and make your gameWidth and height equal to the defaults. Great vids though!

int widthRatio = (int) / DEFAULT_GAME_WIDTH));
int heightRatio = (int) / DEFAULT_GAME_HEIGHT));

int factor = Math.min(widthRatio, heightRatio);

canvasWidth = factor * DEFAULT_GAME_WIDTH;
canvasHeight = factor * DEFAULT_GAME_HEIGHT;

spygear
Автор

I'm confused, why don't you just set the screen size to full screen?:



That's what I did, is it because you want everything scaled at a precise rate?

dimejioladogba