BlueRay101
BlueRay101

Reputation: 1477

How do I adjust my 2D game to every resolution?

I'm coding a 2D game in C# using Windows Forms and the System.Drawing namespace.

The game is basically a battle arena (an orange square) where players shoot at each other. This is how the arena looks like (800x600 resolution): https://i.gyazo.com/54f56cead5c42519678e48118d20947b.png

Since my game is not open world, the requirement is that every player will always see 100% of the battle arena, no matter their resolution.

I have a problem scaling everything to fit the arena with different resolutions.

For example, the game resolution is 800x600, so the arena is roughly 780x580 pixels. The user suddenly resizes the window to 1280x720, so the arena immediately changes to be roughly 1260x700 pixels. It is problematic for one major reason:

The game is designed to be a multiplayer game, where every player can play in a different resolution. There are 2 things that have to be scaled: The position of objects (X,Y) and their size (Width,Height).

I've seen other questions about scaling, but they deal with open-world games, where a lower resolution just means seeing less of the map. In my case, it is a requirement that all the players always see 100% of the game's contents.

I've tried to scale both, but it ends up looking too big or too small due to the scaling of the position being unsuitable for the scaling of the size, or vice versa.

How can I scale everything effectively (so everyone sees 100% of the game's content all the time), especially when multiple users with different resolutions play the game?

Upvotes: 0

Views: 663

Answers (1)

Emond
Emond

Reputation: 50682

Determine the horizontal and the vertical scaling factor and scale both by the smallest factor. This way the entire field will fit. Scale the positions and sizes of the sprites to this factor as well.

Wrap the scaling code in a separate control that hides the factor so the rest of the game can assume a fixed size.

Upvotes: 2

Related Questions