- Home /
Unity for 2D (isometric) pixel art game - how to keep the real size of the sprite in-game?
Hello,
so I am trying to create a 2D game in Unity using pixel art. My problem is that I don't know how I can make sure that my sprite assets stay the same size when they are dragged into the scene? They stay the same size after they've been imported to Unity, of course. I've changed their filtering mode to "Point" as I should.
Here is how it looks now, in a web player (external link): http://svejderud.se/unity/
Here is what the original sprite looks like:
Here is a comparison with the original sprite as it is, and how it looks in the scene view:
As you can see, the sprite has changed size and has distorted the pixel graphics so that it looks just awful.
The problem, as I see it, lies on the orthrographic camera, and its size value. Our game screen will always have fixed resolution of 900x580, and our target platform is Web Player. But how do I know/calculate what value I should insert into the camera's orthrographic Size?
Trial and error approach doesnt work, and is not how it should be solved. I feel there has to be some way to calculate this based off the game resolution or something? My current value is some arbritrary value I experimented with, which as you can see on the images, clearly does not work.
Answer by shimauma · Apr 18, 2014 at 11:05 AM
I found an answer to this on my own. Apparently, I was looking for a term called "pixel perfect", which yielded me this solution:
using UnityEngine;
using System.Collections;
public class PixelPerfect : MonoBehaviour
{
public float floatable = 100.0f; //This can be PixelsPerUnit, or you can change it during runtime to alter the camera.
void Update ()
{
this.camera.orthographicSize = Screen.height * gameObject.camera.rect.height / floatable / 2.0f;//- 0.1f;
}
}
I found this code solution here: http://forum.unity3d.com/threads/210497-Pixel-perfect-2d-in-4-3/page2?p=1513436&viewfull=1#post1513436
Thought I'd post it here if anyone comes across this problem in the future. :)