Hello Guest

Author Topic: Very simple tk2dCamera questions - ortho size? etc.  (Read 11002 times)

vargonian

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 18
    • View Profile
Very simple tk2dCamera questions - ortho size? etc.
« on: June 26, 2012, 08:12:55 am »
In addition to being a question I'm posting on the forum, I'm also requesting that this information be elaborated on in the documentation.  I have been using the 2d Toolkit for a while now and every time I revisit it, I feel like I need to relearn the particulars of how the tk2dCamera works. 

First of all, what is an "ortho size"?  What is this the size of?  What are the units?  What effect is it supposed to have?  How would I know what to do with this field without any description whatsoever of what it is?  Even the tk2dCamera documentation simply lists this as the "Non centered ortho size of this camera." 

Second, how can I simply set my camera bounds (and Game window -- this is important) to, in my example, 768x1024, aka portrait mode on an iPad, but on the PC?  I've set my Player settings to have a 768x1024 resolution.  I've set my Game viewport to be "Standalone (768x1024)".  All looks promising.  All looks good.  I create a Sprite Collection with a Target Height of 1024 (if that makes any difference) and then check the "Use tk2dCamera" checkbox.  I removed the default Unity camera from the scene (so I just have my tk2dCamera).  I click Commit.  I add a sample sprite.

But without fail, every single time, viewable bounds in my Game window are 384x512, exactly half of what I want (or 1/4th if you want to be pedantic).

Can anyone please explain what I need to do to get a 768x1024 game viewport, and more importantly what these settings mean so that I can better understand what I'm affecting when I change these values?  Thanks immensely, and sorry if I sound overwhelmed.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Very simple tk2dCamera questions - ortho size? etc.
« Reply #1 on: June 26, 2012, 08:39:18 am »
I probably take for granted that people know and understand what an orthographic camera is.
From the unity documentation: "Orthographic   Camera will render objects uniformly, with no sense of perspective"

The size of an ortho(graphic) camera is half of how many units it sees vertically. So if the size is 10, the top and bottom coordinates will be -10 to 10 respectively. Units are arbitrary and relative to the size of the scene, and only have any relevance when it comes to physics. A non-centered ortho size refers to the fact that the tk2dCameras origin is on the bottom left of the screen, where 0, 0, = bottom left.

But the problem you're experiencing likely has nothing to do with this. Try this -

In the tk2dCamera, tick "Force Editor Resolution" and type in 768x1024 in there. The tk2dCamera always tries to make the game window pixel perfect, so if you had it scaled down rather than displaying in full resolution, it will use that overridden resolution rather than the number of pixels visible in the game window.

The tk2dCamera has no real parameters apart from this one which is used to force the editor to display at a particular resolution. (well, just ignore resolution override for now). That is because it is built to always scale itself to make 1 world unit = 1 pixel.

Hope that explains it better, and if you have any further questions ,feel free to ask.

vargonian

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 18
    • View Profile
Re: Very simple tk2dCamera questions - ortho size? etc.
« Reply #2 on: June 26, 2012, 06:18:42 pm »
Thanks a lot, I will try this tonight.  One point of confusion is that "ortho size" might be better named "ortho height" in that case, since it's not clear otherwise if it represents width or height. 

I'm always confused as to why my Game window may be set to 768x1024 and yet still doesn't seem to display those dimensions.  I never know if it's the fault of the ortho camera or some quirk in Unity's Game view.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Very simple tk2dCamera questions - ortho size? etc.
« Reply #3 on: June 26, 2012, 06:54:52 pm »
The ortho size, and it referring to the half the height is a standard term in computer graphics - the Unity camera uses the same terminology too.

The game window may be set to 768x1024, but if you resize it in such a way that the window is smaller than 768x1024, Unity will automatically scale this down to fit. It isn't a problem with normal orthographic or perspective cameras as they will automatically scale to fit. With the tk2dCamera, it is meant to fit pixels automatically, and there isn't a way of working out what "resolution" is selected in the game window, so the best it can do is a manual override.

vargonian

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 18
    • View Profile
Re: Very simple tk2dCamera questions - ortho size? etc.
« Reply #4 on: July 01, 2012, 10:43:40 am »
Thanks for that explanation.  I'm definitely familiar with orthographic cameras; I just wasn't familiar with the term "ortho size" and I'm certainly unfamiliar with how Unity's Game window works under the hood.

This solution worked!  And, as an experiment I undocked the Game window and dragged it to my other monitor and made it full screen.  Sure enough, that displayed the coordinates scaled properly (even without the Force Resolution In Editor setting checked.)

I really appreciate your help (and your quick response time!).

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Very simple tk2dCamera questions - ortho size? etc.
« Reply #5 on: July 01, 2012, 01:50:17 pm »
I should really rename it to "orthographic size" to avoid confusion! Thanks for bringing it up.

zinnfandel

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 1
    • View Profile
Re: Very simple tk2dCamera questions - ortho size? etc.
« Reply #6 on: July 02, 2012, 04:15:00 pm »
Hello,
I'm also having trouble with the 2k2dCamera. This here didn't change anything because I'm not having problems seeing things correctly in the editor, but on the iPad itself.

The question is, if my original sprites are smaller than 768x1024, will the camera stretch them or leave them at pixel perfect? Currently I have them at their original size, 640x960, anchored to buttom left.
I checked 2k2dCamera on each sprite and read through the documentation carefully, but I can't find a solution.

Thanks in advance,

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Very simple tk2dCamera questions - ortho size? etc.
« Reply #7 on: July 02, 2012, 07:08:34 pm »
Hi zinnfandel - as explained in the email -
Add a resolution override, set it to 1024x768, and set the scale to 768.0/640.0 (768 divided by 640 = 1.2), and the 960x640 screen will now fit the 1024x768 one. The aspect ratios don't match, so there will be some clipping or empty space.