Hello Guest

Author Topic: Supporting multiple resolutions  (Read 9351 times)

Fanglon

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 1
    • View Profile
Supporting multiple resolutions
« on: May 27, 2012, 07:31:53 pm »
Hello, I've just started using this toolkit (and also unity) and already it looks quite nice and very useful! I've encountered a problem that I don't know how to solve and was hoping that you could help me. I am doing a puzzle game and I am planning to support multiple resolutions (android, iPhone, iPad, PC). I would like the game screen to be scaled as large as it can (keeping the same aspect ratio) and fill the rest of the screen with some filler. In the basic form the filler would be black bars, a more advanced version could be some simple background animation. My base resolution is 480x800. At the moment I am using the tk2d camera and in the sprite collection I have "Use tk2dCamera" checked. If in I use "Force Resolution" for the camera then the screen becomes stretched in different resolutions, if I uncheck it then the sprites keep their absolute and relative (anchors) position in the screen. What would be the best way to achieve the results I want, should I maybe use the original camera?

Thank you.
« Last Edit: May 27, 2012, 07:35:46 pm by Fanglon »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Supporting multiple resolutions
« Reply #1 on: May 27, 2012, 11:21:51 pm »
Hi Fanglon,

With the force resolution tickbox, you have to make sure your game viewport is the same resolution as well for it to work correctly. You will see stretched sprites if the aspect ratios don't match correctly.

In this case, using a normal ortho camera could be a better choice, as you seem to want the sprites to fill up whatever space is available rather than to keep pixel perfection. A normal ortho camera will automatically do this. The tk2dCamera is targetted towards UI / overlay elements / other cases where having pixel sized world units is a nicety.

unikron

outtoplay

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 24
    • View Profile
Re: Supporting multiple resolutions
« Reply #2 on: June 18, 2012, 04:15:52 pm »
Hi Fanglon,

With the force resolution tickbox, you have to make sure your game viewport is the same resolution as well for it to work correctly. You will see stretched sprites if the aspect ratios don't match correctly.

In this case, using a normal ortho camera could be a better choice, as you seem to want the sprites to fill up whatever space is available rather than to keep pixel perfection. A normal ortho camera will automatically do this. The tk2dCamera is targetted towards UI / overlay elements / other cases where having pixel sized world units is a nicety.

unikron


Whoa... So the tk2dCamera is for UI and overlay stuff?  Not my main camera?  Can you clarify?  This is a pretty important distinction.  I actually have a new Post on a related topic, but this I did not know.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Supporting multiple resolutions
« Reply #3 on: June 18, 2012, 04:28:45 pm »
There really isn't a distinction, and one isn't for one or the other purpose specifically. Its just that it tends to suit UI mainly because of the pixel sized world units, etc. You're free to use it either way.

CliffCawley

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 34
    • View Profile
Re: Supporting multiple resolutions
« Reply #4 on: October 14, 2012, 01:25:00 pm »
If the 2d Camera is more for UI/Overlays, how can I combine the 2d Camera and an Ortho Camera in the same scene?

The usual way of using Clear Flags to ignore and Depth for rendering order doesn't work.

In the docs it says you can only have 2d Camera in the scene, with no other Cameras.

Can I use an Ortho camera for my game scene and the tk2dCamera for my Overlay/UI and if so how?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Supporting multiple resolutions
« Reply #5 on: October 14, 2012, 05:08:25 pm »
You can definitely set up 2 cameras in the same scene (a tk2dCamera is just a camera with a custom projection matrix so nothing special there).

1. Set up your ortho/perspective camera for your game. Make sure layer is set up to ignore everything the tk2dCamera will see.

2. Set up your tk2dCamera, set clear flags to Depth only or Dont Clear. Make sure Depth (on the camera inspector) is larger the Depth value of the camera from step #1.

I just tested this on tk2d 1.76 + patch 3 on Unity 3.5.6f4 to make sure - it works fine.


CliffCawley

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 34
    • View Profile
Re: Supporting multiple resolutions
« Reply #6 on: October 15, 2012, 12:41:23 am »
Huh.

I just tried again and it worked just fine.

I have no idea what went wrong, perhaps it was just tiredness.

Thanks, all sorted now!

:)