I’m trying to figure out the best way to get my Canvas to match my game resolution when using low-res pixel art (approximately 16x16).
I’m after a clean look, where all the UI elements adhere to the exact same resolution as the actual in-world sprites. If there’s any discrepancy then pixel art suddenly looks messy.
Has anyone had any luck with this?
I’m using this plugin to ensure I get pixel perfect sprites (it dynamically changes the orthographic camera’s “Size” value).
Using “Scale With Screen Size” gives varying results depending on the resolution, so I can’t guarantee it will always be the same as my sprite resolution.
Take a look at this…
This is the same source image rendered as a sprite and a UI image overlaid on top of each other. Ideally, they should be identical. How can I achieve that at any arbitrary screen size?
I posted this earlier but it may be relevant in this case.
You can try attaching it to your camera so long as you have a constant aspect ratio and camera size
using UnityEngine;
public class CameraScaler : MonoBehaviour {
public float orthographicSize = 16.875f;//set this to your camera size
public float aspect = 16/9;//set this to your aspect ratio
void Start()
{
Camera.main.projectionMatrix = Matrix4x4.Ortho(
-orthographicSize * aspect, orthographicSize * aspect,
-orthographicSize, orthographicSize,
Camera.main.nearClipPlane, Camera.main.farClipPlane);
}
}
This doesn’t appear to help. In fact it just seems to warp my aspect ratio so the game looks like this:
It should look like this:
Am I doing something wrong?
Maybe I’m failing to understand something about your script but I’m seeing how it relates to the issues I’m having with the Canvas. If I activate the component while the game’s running I don’t see any change in the way the canvas is rendered.