Salomonsson.se
Oct 01 2014

pixel perfect tiles in unity

I was wrestling a bit with how to get my tiles 1:1-scale. Turns out this is the way to go:

  • Set camera to orthographic (2d), and set the size to screen height/2. Since I optimize for PS Vita screen (960×544) that’s 272.

  • Now the tiles are super tiny. That’s because I created the vertexes with 1 unit as spacing. My tiles are 64×64 so I can either re-write all my vertexes (multiply them with 64). OR we can keep the 1-unit vertexes and divide the camera size (272/64 = 4.25)

Bingo! Will probably cause some problem when I have to move my sprites by 1/64 per pixel… That’s future Tommy’s problem though =) Oh, and if you have a dynamic size of your screen you can use Screen.height;

Edit (2016-12-14): here is a good blog post from Unity about pixel perfect 2d in Unity: https://blogs.unity3d.com/2015/06/19/pixel-perfect-2d/