Hello Guest

Author Topic: Issue: tk2dCamera viewport Squishing at Edge of Screen  (Read 7579 times)

firmie

  • Newbie
  • *
  • Posts: 15
    • View Profile
Issue: tk2dCamera viewport Squishing at Edge of Screen
« on: May 24, 2014, 05:13:46 pm »
Problem:
tk2dCamera viewport is being squished at the edge of the screen instead of going offscreen.

I have multiple cameras being rendered on screen at one time. I manage where their viewport rects are output based on player input. I would like these to be able to go offscreen, but when they get to the edge of the screen, they will compress and not go beyond the screen boundaries, effectively ‘squishing’ that viewport rect. Oddly enough, I’m printing out the CameraSettings viewport rect and the numbers dont seem be skewed by the screen edge.

This does not happen when I try it with normal Unity Cameras, they will correctly move on and off screen partially. It's only a problem with tk2dCameras. Any ideas how I can get the viewports to not ‘squish’ at the edges of the screen?

Thanks

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Issue: tk2dCamera viewport Squishing at Edge of Screen
« Reply #1 on: May 24, 2014, 10:04:09 pm »
I don't think I understand, can you post some screenshots? The tk2dcamera simply uses the unity viewport stuff, so should make no difference either way.

firmie

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: Issue: tk2dCamera viewport Squishing at Edge of Screen
« Reply #2 on: May 25, 2014, 12:29:12 am »
Turns out this is a Unity viewport issue. By coincidence, the example I was using was showing the tk2dCamera incorrectly but not the normal cam next to it.

This is a better explanation of my problem:

http://answers.unity3d.com/questions/328262/how-to-slide-a-second-camera-on-off-screen.html

Thanks,

atamize

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Issue: tk2dCamera viewport Squishing at Edge of Screen
« Reply #3 on: May 31, 2014, 05:02:58 pm »
I am experiencing a similar issue. The weird thing is, I am getting the results I want inside the Unity editor, however if I build a standalone or iOS version, I get a stretched image on both viewports (when their rects are not set to default values).

The context is, I have 2 cameras: camera1 is drawing the right side of the screen, camera2 the left. As I increase camera1's rect.x, camera2's rect.width increases the same amount to fill in the gap.

I do not have any resolution overrides on my tk2dCameras.

Is there a way I can get the same results in the standalone as I do in the editor?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Issue: tk2dCamera viewport Squishing at Edge of Screen
« Reply #4 on: May 31, 2014, 07:05:23 pm »
What version of tk2d are you using? What do you want it to do? You could try the pixel perfect override to see if it helps. The behaviour of this has changed over versions. Also check your resolution in the game window, that is the main thing I could think of that would be different with the editor and runtime.

atamize

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Issue: tk2dCamera viewport Squishing at Edge of Screen
« Reply #5 on: May 31, 2014, 08:22:43 pm »
I'm using version tk2d version 2.4.0 on Unity 4.5.0f6. What I want it to do is not stretch the image when I change the viewport rect x or width (which is true when running in the editor). The pixel perfect override gives the same result as not having any override. The resolution of the game window is the same in the editor as the standalone build, but the issue occurs regardless of resolution.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Issue: tk2dCamera viewport Squishing at Edge of Screen
« Reply #6 on: May 31, 2014, 08:58:00 pm »
I could test this to see whats going on if you can make a little repro case. I am not sure why its behaving differently in the editor to the game, I cant see any code that does stuff differently (except for the resolution detection).

atamize

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Issue: tk2dCamera viewport Squishing at Edge of Screen
« Reply #7 on: May 31, 2014, 09:36:57 pm »
Import this package into a project with tk2d already imported. Open the Test.unity scene. There should be a sprite in the scene pointing to the 2D toolkit logo, but really you can use any sprite to see the effect.

Run the game in the editor. Drag the slider to move the current camera's viewport rect x value. You can switch between the tk2dCamera and Unity camera. Notice there is not really a difference between them and the sprite retains its shape.

Now build and run a standalone version. Notice that dragging the slider with the tk2dCamera causes the image to distort, whereas using Unity camera does not cause distortion.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Issue: tk2dCamera viewport Squishing at Edge of Screen
« Reply #8 on: June 01, 2014, 07:11:58 pm »
Hi,
Thanks for the repro, wouldn't have found it otherwise. This is happening because the camera.pixelwidth is changing when the rect is changing - and in the editor, the game mode override is overriding this value. You can fix it by changing 2 lines in tk2dCamera -
I will need to figure out the implications of changing this behaviour - the tk2dcamera supports that now legacy clip anchored region feature, which needed it to behave in this way, but that feature is now deprecated.

   Vector2 GetScreenPixelDimensions(tk2dCamera settings) {
      Vector2 dimensions = new Vector2(ScreenCamera.pixelWidth, ScreenCamera.pixelHeight);
      Vector2 dimensions = new Vector2(Screen.width, Screen.height);

   public tk2dCameraResolutionOverride CurrentResolutionOverride {
      get {
         tk2dCamera settings = SettingsRoot;
         Camera cam = ScreenCamera;

         float pixelWidth = cam.pixelWidth;
         float pixelHeight = cam.pixelHeight;

         float pixelWidth = Screen.width;
         float pixelHeight = Screen.height;


atamize

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Issue: tk2dCamera viewport Squishing at Edge of Screen
« Reply #9 on: June 01, 2014, 08:19:26 pm »
That did the trick. Thanks for the help!