11

« **on:** May 19, 2015, 12:56:47 AM »
Well, the number 704 isn't really chosen for any reason other than what we like the view distance to be.

Here is the code that sets the scale:

`if (WorldDrawer.RenderSettings.LetterBox)`

height = (int)Math.Round(width / (16f / 9f));

Width = width;

Height = height;

var idealScale = (height + width) / 44;

if (width / (float)height > 2.5f)

idealScale = height / 16;

int scale;

var scales = new[] { 16, 32, 48, 64, 80, 96, 112, 128, 144, 160, 176, 192 };

for (scale = 1; scales[scale] < idealScale; scale++) ;

if (Math.Abs(idealScale - scales[scale]) > Math.Abs(idealScale - scales[scale - 1]))

scale--;

cam.ScaleFact = scales[scale];

So I set the ideal scale to be "(height + width) / 44", then I adjust it to get an even multiplier of the pixels so that we can have pixel-perfect rendering. That 44 gets multiplied by 16 in the render code since 16 is the scale that the sprites are at (and 44*16 is 704). So changing that zooms the camera in or out and we just set it to whatever we thought was good.

This breaks at weird aspect ratios which is why I added the "if (width / (float)height > 2.5f)" check.