Hello Guest

Author Topic: using tk2dCamera help  (Read 4868 times)

xikky

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 20
    • View Profile
using tk2dCamera help
« on: January 31, 2013, 09:57:59 am »
I am having problems when using the tk2dCamera object and would really appreciate some help.

So what I am doing? I created a background image for testing purposes with a resolution of 1280x720 which I have put in a sprite collection (with use tk2dCamera ticked) and produced a sprite object with this background image texture. I have then added a tk2dCamera and I am now trying to fix the whole image on the screen.

I have set camera size to 100
I have set the native resolution to 1280x720
I also set the camera resolution to 640x360 and also fixed the game window to match the same resolution

Went back to the background sprite inspector, and clicked 1:1 button for pixel perfect texture. The texture was scaled from 1 to 360 in all axis and this resulted in the camera displaying a zoomed area of the image.

I went back to the camera object and added an override resolution of 640x360 and a scale of 0.0014. And as a result, the whole image was now displayed on the camera.

If I delete the tk2dCamera and create a normal unity camera object with size 100, and then I go in the sprite collection and untick the use with tk2dCamera and set the height to 720, and click on the 1:1 button on the sprite object, the whole image is displayed in the camera.

I would like to ask you if in both cases the background image is at pixel perfect? and what is the difference between the two as in features, advantages and disadvantages?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: using tk2dCamera help
« Reply #1 on: January 31, 2013, 11:16:45 pm »
1. In your sprite collection containing the background image, go into settings, tick "Use tk2dCamera" and commit. The sprite should now be created at native size automatically, no need to click anything.

2. In the tk2dCamera, set native resolution to 1280x720, preview resolution as you have it, but you don't need to add an explicit override like that, just create a default one and leave it as is. It will automatically scale to fit content.

In both your cases, the background images should be pixel perfect.

The advantage to using the tk2dCamera is that world points = pixels, so x=100 y=50 is 100 pixels from the bottom of the screen, and 50 pixels from the left of the screen.
tk2dCamera also does scaling and other forms of aspect ratio compensation for different resolutions and aspect ratios. The override is one example. If you ran your game on a 1280x768 resolution, it would still fit the screen. It would be letterboxed, but it would still work. You'd have to implement all of that yourself with a normal camera.

xikky

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: using tk2dCamera help
« Reply #2 on: February 01, 2013, 01:41:36 pm »
Thank you for your reply unikron.

One last small thing.. when I click on the "1:1" (make pixel perfect) button on the sprite, it is scaled a much bigger size. Why is this so? when should I use this button?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: using tk2dCamera help
« Reply #3 on: February 01, 2013, 02:20:33 pm »
The 1:1 button is only required when you're creating a sprite at a different native resolution. For instance, if you create a sprite in a perspective camera, it most likely wouldn't be drawn at 1:1. There are various other reasons your sprite might not be created pixel perfect, and this button fixes it for the primary camera.

xikky

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: using tk2dCamera help
« Reply #4 on: February 01, 2013, 02:38:13 pm »
Much more clear now. Thanks you for the help :)