Phantom camera translation when trying to set screen size

Hi, I’m making a 2D pixel-art-based platformer and I’m trying to make it look as close to a Super Nintendo game as Unity will allow me to.

The game is shaping up well, but I’m having trouble getting the resolution correct without distorting the graphics.

Super Nintendo games tended to have a resolution of 256 x 224 pixels, and I would like to have my game render at this resolution, but display magnified 2x in a window of size 512 x 448 pixels.

First of all, my graphics are displayed at 1 pixel per unit, as I felt that this would make it easy for me to move elements around one whole pixel at a time.

Secondly, my player settings show a resolution of 256 x 224.

I have put this code in my camera script:

camera.aspect = 512 / 448;
Screen.SetResolution(512, 448, false);
Camera.main.orthographicSize = Screen.height/4;

This results in a window of the desired size (512 x 448), and my graphics appear to be in the correct places, but they are distorted. Some pixels are stretched slightly horitontally.

If I comment out the aspect ratio line from the code, the pixels display perfectly, but the camera is translated by 20 pixels to the left compared with how it appears in Unity’s game view (with the game view set to the resolution in player settings).

Anyone know how to achieve what I’m trying for? I feel I’m close, but need a bit of help.

Thanks!

EDIT: The 20 pixel offset can be ignored, I think that is coming from a calculation involving the camera’s position.

I can now achieve the result I want when building, but when I press play in the game view, the view stays the size of the smaller resolution, while the graphics within it scale up to twice their size (as they would be in the doubled-resolution build).

I solved this myself.

I just had to change the player settings resolution to 512 x 488, leaving the aspect ratio code disabled. The 20 pixel shift was a result of a camera position calculation that needed altering for the new resolution.