Sunday, July 17, 2016

How would you handle different aspect ratios in a 2d platformer?


A long time ago, 4:3 was pretty much the only apect ratio you would find on a PC. Today the most common one is 16:10, but most new monitors (especially laptops) are 16:9


I'm writing a 2D platformer, and I can't decide how I should handle all the different ratios.



Here are some ideas:



  1. 4:3 gets more content, widescreens are cut on top and bottom

  2. 16:9 gets more content, the others are cut left and right

  3. The game is in 16:9 with black horizontal bars for other ARs

  4. The game is in 4:3 with black vertical bars for other ARs



Answer



If you have no compelling reason to make your game "wide" (in which case use approach 3) or narrow (in which case use approach 4), go with a combination of 1 and 2 (or possibly 3 and 4 if you want to hide things off-screen).


Select a compromise aspect ratio (16:10 is a good one, or even 16:11). If the user is on 16:9 give them more content to the side, and if they're on 4:3 give them more content at the top and bottom.



In any case - I find it best to implement it with something like this in your camera class:


float scaleToFitWidth = viewport.Width / nominalWorldSize.Width;
float scaleToFitHeight = viewport.Height / nominalWorldSize.Height;
float scale = Math.Min(scaleToFitWidth, scaleToFitHeight); // world to client

At which point you can simply experiment with different nominal world sizes (ie: the size of the camera in world units) and simply select the best one.


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...