Hello Guest

Author Topic: Need help binding a camera within the playing area's limits  (Read 5267 times)

Quells122

  • Newbie
  • *
  • Posts: 18
    • View Profile
Need help binding a camera within the playing area's limits
« on: January 13, 2015, 03:14:42 am »
I'm using a tk2D camera, and I'm trying to bound the camera view within the game's map area. The game doesn't follow pixel perfect snapping rules and the tricky part is that the camera is allowed to zoom in and out.

I found this link online that recommends using a camera's orthographic size property. However, I noticed that a tk2D camera doesn't change its orthographic size property with the zoom level.
the link-> http://answers.unity3d.com/questions/501893/calculating-2d-camera-bounds.html

I'm wondering if the tk2D camera has some functions that lets me query the state of the camera's field of view since orthographic size seems unavailable.

On a side note, I noticed that orthographic size is set to 480. My game uses tiles that are 16x16 pixels. Is 480 orthographic size too big? Changing it doesn't seem to have any visible effect on the game...

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Need help binding a camera within the playing area's limits
« Reply #1 on: January 13, 2015, 02:14:37 pm »
If you're using a tk2dCamera, then getting tk2dCamera.ScreenExtents will get you a Bounds object with xMin / xMax / yMin / yMax. You just need to make sure that it never exceeds that. ScreenExtents gives you the world space extents of the camera.

Quells122

  • Newbie
  • *
  • Posts: 18
    • View Profile
Re: Need help binding a camera within the playing area's limits
« Reply #2 on: January 14, 2015, 06:05:23 am »
Thanks! ScreenExtents was exactly what I needed.

What about the camera's orthographic size? Changing it doesn't seem to do anything. Does it not matter what that is set to?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Need help binding a camera within the playing area's limits
« Reply #3 on: January 14, 2015, 10:50:19 am »
Orthographic size isn't used in tk2dCamera - tk2dCamera is by default pixel perfect and everything is relative to that.