Author Topic: Does using TweenScale reset the camera size?  (Read 9394 times)

technoir

  • Newbie
  • *
  • Thank You
  • -Given: 3
  • -Receive: 1
  • Posts: 27
    • View Profile
Does using TweenScale reset the camera size?
« on: November 07, 2014, 11:14:08 AM »
Hi

I have a zoomed cam and would like to scale up a sprite at this zoom. However, as soon as the scaling begins, the cam seems to reset back to size 1.

Any Ideas?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Does using TweenScale reset the camera size?
« Reply #1 on: November 07, 2014, 03:58:24 PM »
NGUI was designed to work with camera orthographics size of 1. Not sure what you're doing there, as nothing in NGUI tweens orthographic size, and changing the transform scale of a camera does nothing.

technoir

  • Newbie
  • *
  • Thank You
  • -Given: 3
  • -Receive: 1
  • Posts: 27
    • View Profile
Re: Does using TweenScale reset the camera size?
« Reply #2 on: November 08, 2014, 10:29:07 AM »
Oh I see, OK thanks for letting me know.
Well what I need to be able to is zoom in and out of a background (a map). How would you recommend I approach this?

Thanks

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Does using TweenScale reset the camera size?
« Reply #3 on: November 09, 2014, 09:04:01 PM »
Scale the transform of the map object.

technoir

  • Newbie
  • *
  • Thank You
  • -Given: 3
  • -Receive: 1
  • Posts: 27
    • View Profile
Re: Does using TweenScale reset the camera size?
« Reply #4 on: November 14, 2014, 11:59:56 AM »
OK great, thanks - I'm currently looking into this.

The way I'm approaching it is by first calculating the correct size Rect bounding box around the colliders of a set of buttons on the background. I would then like to scale the background up so that when scaled, it fills the screen with what's in the bounding box (I think this should be the same as how pinch-zooming works?).

I have implemented the Rect and it's surrounding the buttons correctly. However, I'm having some trouble calculating the scale that I need to use on the background. I know that I need to do some conversions to different coordinate systems but not sure where. I have tried converting the bounding box from screen to World coords but this doesn't seem to be working.  My scaling function is as follows;

  1. float CalculateMapScale(Rect boundingBox)
  2. //    float CalculateMapScale()
  3.     {
  4.         // Cache the map's size.
  5.         Vector3 mapScale = Map.transform.localScale;
  6.  
  7.         // Find the Map width and height. - In World coords
  8.         float mapWidth = RightAnchor.position.x - LeftAnchor.position.x;
  9.         float mapHeight = TopAnchor.position.y - BottomAnchor.position.y;
  10.  
  11.         // Calculate the Map aspect ratio.
  12.         float mapAspect = mapWidth / mapHeight;
  13.        
  14.         // Work out the Width and Height scales relative to the bounding box.
  15.         float newMapWScale = mapWidth / Mathf.Abs(boundingBox.width);
  16.         float newMapHScale = mapHeight / Mathf.Abs(boundingBox.height);
  17.  
  18. /*
  19.        Vector3 bbBottomLeft = NGUICam.ScreenToWorldPoint(new Vector3(boundingBox.xMin, boundingBox.yMin, 1));
  20.         Debug.Log("bbBottomLeft = " + bbBottomLeft);
  21.  
  22.         Vector3 bbTopRight = NGUICam.ScreenToWorldPoint(new Vector3(boundingBox.xMax, boundingBox.yMax, 1));
  23.         Debug.Log("bbTopRight = " + bbTopRight);
  24.  
  25.         Vector3 bbWidthHeight = bbTopRight - bbBottomLeft;
  26.         Debug.Log("bbWidthHeight = " + bbWidthHeight);
  27. */
  28.  
  29.         float newMapScale = 0;
  30.  
  31.         if (newMapWScale >= newMapHScale)
  32.             newMapScale = newMapWScale;
  33.         else
  34.             newMapScale = newMapHScale;
  35.  
  36.         return newMapScale;
  37.     }

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Does using TweenScale reset the camera size?
« Reply #5 on: November 15, 2014, 04:21:50 PM »
What's a bounding box in this case, and why would it be in screen space?

Widget coordinates are defined by widget.worldCorners[]. There are 4 corners, so 4 values. These values are in world space, not screen space.