Hello Guest

Author Topic: Game resolution problem problem when building and run  (Read 4841 times)

ryf9059

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 41
    • View Profile
Game resolution problem problem when building and run
« on: June 10, 2013, 11:38:03 am »
So I have establish a scene using collection of value 2.5 target ortho size and 900 target height. So the game runs pixel perfectly at ortho camera size of 2.5 and resolution of 1600x900.

When building and running the game there is a window asking you to choose resolution, defaulted at 1600x900, however you could choice other resolutions. The problem is, now matter what resolution I choose, it display rougly the same area of game but those textures are either up sampled or down sampled, the aspect ratio is kept for textures.

This simply chagnes the window size but didn't actually change the resolution. I want the window to display more content at higher resolution and less at lower resolution but those sprites should be pixel perfect in all senarios. What should I do to achieve this? Clearly I cannot change the target height in the collection just to fit one resolution and it breaks the scene anyways.

Please advice.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Game resolution problem problem when building and run
« Reply #1 on: June 10, 2013, 11:40:48 am »
No, but you can change the ortho size of the camera to make things pixel perfect again. Use something like this to rescale it to be always pixel perfect.

Code: [Select]
float pixelHeight = camera.pixelHeight;
float newOrthoSize = pixelHeight / (float)initialCameraHeight * initialCameraOrthoSize;
if (camera)
{
camera.orthographicSize = newOrthoSize;
}

ryf9059

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 41
    • View Profile
Re: Game resolution problem problem when building and run
« Reply #2 on: June 10, 2013, 02:07:26 pm »
No, but you can change the ortho size of the camera to make things pixel perfect again. Use something like this to rescale it to be always pixel perfect.

Code: [Select]
float pixelHeight = camera.pixelHeight;
float newOrthoSize = pixelHeight / (float)initialCameraHeight * initialCameraOrthoSize;
if (camera)
{
camera.orthographicSize = newOrthoSize;
}


Where should I put this code?
The resolution window only appears after I use build and run:



unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Game resolution problem problem when building and run
« Reply #3 on: June 10, 2013, 02:11:21 pm »
Not there - in the game. Create this script and attach to your main ortho camera.

Code: [Select]
using UnityEngine;
using System.Collections;

public class tk2dOrthoCameraSizer : MonoBehaviour
{
public float initialCameraOrthoSize = 1.0f;
public int initialCameraHeight = 640;

// Use this for initialization
void Start ()
{
UpdateCamera();
}

void UpdateCamera()
{
float pixelHeight = camera.pixelHeight;
float newOrthoSize = pixelHeight / (float)initialCameraHeight * initialCameraOrthoSize;
if (camera)
{
camera.orthographicSize = newOrthoSize;
}
}

// Update is called once per frame
void Update ()
{
}
}

ryf9059

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 41
    • View Profile
Re: Game resolution problem problem when building and run
« Reply #4 on: June 10, 2013, 02:57:40 pm »
Thanks it worked. I just have to change the parameter initialCameraOrthoSize and initialCameraHeight to my default so it scales correctly.