Hello Guest

Author Topic: Modify Camera Viewport Rect in javascript (tk2d 2.4 beta 3)  (Read 5093 times)

a55b0t

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 2
    • View Profile
Modify Camera Viewport Rect in javascript (tk2d 2.4 beta 3)
« on: March 10, 2014, 03:43:50 am »
Hi,

I'm curious if I can access the camera viewport rect in script now. I am using myCamera.rect = Rect(X,Y,W,H) and it doesn't seem to be working.

Basically I am trying to use a square camera in the middle of the screen for gameplay / menus, and using an overlay to cover the rest of the screen depending on the aspect ratio.

I was also wondering if I need to use anchored viewport clipping, but my overlay is loaded in a separate scene so it stays consistent across the game (making me unable to link the cameras).

As an aside, I've been playing around with some nested layout container sizers but haven't been having a lot of luck. Is it okay to parent them to each other? I'll try to work with them a bit more so I can provide some better details..

Thanks for the great product. Other than a few snags here and there it's been a great help to me on multiple projects.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Modify Camera Viewport Rect in javascript (tk2d 2.4 beta 3)
« Reply #1 on: March 10, 2014, 10:24:58 am »
You don't need to use anchored viewport clipping, just use the normal unity viewport rect stuff. tk2dCamera.camera.rect = zzzz; should work fine, but not if you have anchored clipping, etc on. Also make sure you're on 2d toolkit 2.4 beta, as some issues with viewports were fixed there.

a55b0t

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Modify Camera Viewport Rect in javascript (tk2d 2.4 beta 3)
« Reply #2 on: March 16, 2014, 07:53:41 pm »
Thanks. I had some other issues I fixed that were causing problems as well so it took me a while to track it down.

I did have to use tk2dCamera.CameraSettings.rect for it to work in the end though.

Izitmee

  • 2D Toolkit
  • Jr. Member
  • *
  • Posts: 99
    • View Profile
    • Holoville Games
Re: Modify Camera Viewport Rect in javascript (tk2d 2.4 beta 3)
« Reply #3 on: November 05, 2014, 11:28:34 am »
Thanks for the info a55b0t, I was getting crazy trying to change the camera rect at runtime. CameraSettings.rect is the only way to go, otherwise tk2dCamera apparently resets its rect values at every frame.