Hello Guest

Author Topic: Help me correct my thinking on resolutions.  (Read 8089 times)

Porthos

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 13
    • View Profile
Help me correct my thinking on resolutions.
« on: June 12, 2012, 12:28:12 am »
I wanted to target 1280 x 720 because I wanted a 16 x 9 resolution, and this seemed like a fairly low one that most screen should be able to handle.

I am using 16 by 16 (and 16 x 32) pixel sprites in an rpg setting to give the project a snes RPG feel.

I wanted each sprite to be exactly 1 x1 Unity units so that I so that coding walking on a grid will be clear and easy.

I am using ortho 8 (so that I can see about 8-9 'squares around my character in the over world map) and I have the setting set right in Sprite collection.

In order to get the sprite the correct size, (1x1 Unity units) I have to multiply the sprite by 2.8125 in the Sprite Collection.
This leads to the 'pixels' being off. Some pixels are slightly larger than others (no fault of 2d toolkit it just does not divide evenly).

My question is, where am I going wrong with this setup? I can tell that I don't know anything about resolutions. Should I just use the default size and just somehow deal with every coordinate in my grid being a long decimal? Am I misunderstanding something about scaling? Is the resolution I have chosen even reasonable? I there anything else wrong about the way I am approaching this?

theremin

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: Help me correct my thinking on resolutions.
« Reply #1 on: June 12, 2012, 02:58:32 am »
Preface: I'm still new to Unity and 2D Toolkit, so take my advice with a grain of salt. Definitely pay more attention to unikron; he's the smart guy here :)

But I'll throw in my $0.02:

If it's not too late to switch to a tk2dCamera, I highly recommend that. It will make your life so much easier. tk2dCamera makes sprite positioning simple. Want to move a sprite 1 pixel to the right? Just add 1 the transform.position.x value. You'll never get any of those "off" pixels.

Also, depending on how flexible you want to be with your resolution support (sounds like you're OK with forcing 1280x720, and if you want to stick with that, that's fine --- just ignore this): With blocky retro style pixel graphics, using the tk2dCamera's Resolution Override to scale your graphics works really well for keeping your looking fairly consistent at a variety of native resolutions. You might have a scale of 1:1 for really old displays (e.g., 640x480), and then a scale of 2:1 for 1280x720 (and 1280x800), and a scale of 3:1 for 1920x1080 (and 1290x1200)... and perhaps even beyond e.g., for the new MacBook Pro retina display announced today. That will guarantee nice sharp retro pixel graphics at every resolution. But that may not work for you, especially if you're using 1280x720 for 1:1 pixels. Just wanted to throw the idea out there.

I'm using a similar concept for a retro style pixel game I'm making, with support for a wide variety of resolutions:
- 480x320 on the iPhone 3GS
- 960x640 on the iPhone 4/4S
- 1024x768 on the iPad
- 2048x1536 on the iPad 3
- 1280x720, 1280x800, 1920x1080, and 1920x1200 (and beyond) on PC and Mac.

And I throw this script on my tk2dCamera, and 2D Toolkit makes a whole lot of magic happen:

Code: [Select]
void Awake()
{
tk2dCamera.inst.resolutionOverride = new tk2dCameraResolutionOverride[1];
tk2dCamera.inst.resolutionOverride[0] = new tk2dCameraResolutionOverride();
tk2dCamera.inst.resolutionOverride[0].width = Screen.width;
tk2dCamera.inst.resolutionOverride[0].height = Screen.height;

if (Screen.height >= 1280)
tk2dCamera.inst.resolutionOverride[0].scale = 4f;
else if (Screen.height >= 960)
tk2dCamera.inst.resolutionOverride[0].scale = 3f;
else if (Screen.height >= 640)
tk2dCamera.inst.resolutionOverride[0].scale = 2f;
else
tk2dCamera.inst.resolutionOverride[0].scale = 1f;
}

Note: The scale values above are just ballpark, obviously you'd have to use whatever works for your particular circumstances.
« Last Edit: June 12, 2012, 04:28:26 am by theremin »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Help me correct my thinking on resolutions.
« Reply #2 on: June 12, 2012, 10:17:02 am »
As theremin says, the tk2dCamera is probably the easiest thing to use here, as all round world coordinates there will be pixel-aligned, so the spacing between tiles will be 16, always, regardless of resolution.

Alternatively, you can work out exactly the coordinates you need for a normal ortho camera.
In your case, say you're using a 1280x720 target "native" resolution, and your tile size is 16x16
The ortho size should be (720 / 16) / 2 = 22.5
One world unit in this camera should be exactly the dimensions of one tile there, and there shouldn't be any gaps. Going back to the tilemap editor, if you're using that there, then you should go to Settings > Tile Properties, and "Reset" after you've done this.

You can use this auto-scaling script to get it to autoscale for other resolutions -
http://unikronsoftware.com/2dtoolkit/forum/index.php/topic,262.0.html

Porthos

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Help me correct my thinking on resolutions.
« Reply #3 on: June 13, 2012, 03:06:21 am »
Ok, sound like tk2dCamera is the way to go, but thanks for the calculation too. Now I realize that ortho size is not just an arbitrary number.

I switched everything to the tk2dCamera settings and added theremin's script to the awake function of the Tk2dCamera script. Messed with the values a bit, everything looks great (after it actually compiled, you ever have unity seemingly forget to compile on you?) .


Just two questions:

1. What 'resolution' am I actually dealing with now (what height is the top of the screen)? It looks like 256. Is this understanding correct?

2. What is the best way to deal with the game window? Is there a way to set it to say exactly 1280x720 so I can see exactly what it will look like at that resolution?

Thanks for all the help.

theremin

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: Help me correct my thinking on resolutions.
« Reply #4 on: June 13, 2012, 05:28:29 am »
If you're not very comfortable with resolution stuff yet, you may want to stay away from that little script I provided for the time being. It may cause more harm than good until you have a good grasp on resolutions.

The best way to figure out what resolution you're running at is to throw the line Debug.Log(Screen.width+","+Screen.height); somewhere into your code, and watch the output in the console. It's important to play around with different resolutions to get a sense of how your game will look on each. Go to Edit > Project Settings > Player to set the default screen width and screen height, and then, in the Game window, make sure that "Standalone (Width x Height)" is selected. Also make sure "Maximize on Play" is active.

As far as I can tell, as long as your monitor's resolution is larger than the default screen width and screen height you chose, you'll see your game at your preferred resolution. I haven't been able to figure out how to make Unity play a game in-editor at my monitor's full native resolution yet though. (The game doesn't fit with Unity's menus, toolbars, and status bars, so Unity seems to shrink it down to a resolution that fits.)