I'm new to Unity and I would like someone to help me out in this particular problem. I created a 2d jigsaw puzzle game. One of the scripts is a loader that creates a number of tiles (a prefab consisting of just a plane scaled to 1,1,1) and assigning a different texture to each. The whole puzzle has a resolution of 1024 * 768 pixels. Each tile has a resolution of 256 * 256 pixels (extra pixels are transparent).
The problem arises when trying to load the puzzle in different resolutions. For example if I load the game in a screen resolution of 1920,1200 and a screen size of 1024,768 - the puzzle tiles look smaller than they should. How can I scale the textures so that they look the correct size? What solution do you suggest to display a texture in its correct size? BTW the camera is set to orthographic with an orthographic size of 2.5.
asked Jul 23 '10 at 12:12 PM
Your problem consists of two different aspects: Geometry size and texture resolution.
If you created your game for 1024x768, which would mean you have exactly 4x3 tiles of 256x256 textures, then thefirst part is to either scale your geometry to fit the new resolution, or change the Camera's field-of-view.
If all your tiles are grouped in one GameObject, you need to adjust the scale of that GameObject by Screen.height/768.0. As a result, your 4x3 tiles will be scaled to completely fill the vertical screen space, and depending on the aspect ratio of your new resolution all or some of your horizontal screen space. For example, for a resolution of 1920x1200 (aspect ratio 1:1.6), Screen.height is 1200, which results in scaling by a factor of 1.5625. However, 1024*1.5625 is only 1600, not 1920, so there will be borders right and left of your puzzle (you do not want to stretch your tiles to 1920-width, this will generally look ugly).
Instead of scaling the geometry, you'll get an identical result if you scale the field-of-view (or in your case, the Camera.orthographicSize) by the reverse value 768.0/Screen.height (I think - never really worked with orthographic cameras).
The second part of your problem are the texture sizes. As equalsequals points out, scaling the geometry but not the textures will result in blurry textures for larger resolutions. You don't need to adapt your texture sizes exactly to the screen resolution (i.e., by the factor 1.5625), you just should make sure that your textures are AT LEAST AS LARGE AS the maximum resolution. So if you assume that the maximal resolution you puzzle is ever used at has a height of 1200, then your textures should have at least a resolution of 256*1200/768=400. So you should create your tiles with 400x400, or even better 512x512, and then play around with the import settings (enabling mipmaps, trying both Bilinear and Trilinear at small and large resolutions). Using 512x512 has the advantage of better Mipmap-Filtering, which you need when using smaller resolutions.
answered Aug 06 '10 at 06:02 PM
Thanks for clarifying that you are mapping these 256^2 textures to 1x1 planes. I'm not sure if this is the solution to your problem but I'm going to take a shot in the dark here and hope for the best.
Unity should automatically resize everything in 3D space (not GUI because that is 2D space) as your resolution changes.
This part of your question confuses me:
If you could explain that a little better I will edit my answer if this does not solve your problem.
Anyway - on to my shot in the dark.
There is something we refer to as Texels which is where you should direct your attention.
Since these 3D objects are vector based with a bitmap graphic covering it, all you need to do is make your planes larger and the texture scales accordingly.
Keep in mind that you should never break the 1:1 ratio -
i.e. If your plane has a 256x256 texture it shouldn't be rendered larger than 256x256 else you get the fuzzy, pixelated results you get by zooming in on an image past it's actual size.
You should figure out how much larger your resolutions are an scale these 3D objects accordingly (including padding and such.)
For instance 1024x768 resolution is 28% larger than 800x600 (800*1.28 = 1024 & 600*1.28 = 768) so in jumping between those 2 resolutions your 1x1 plane should become 1.28x1.28
Hope that helps, again just a shot in the dark here.
answered Jul 23 '10 at 04:24 PM