Author Topic: Size of Sprite is issue after upgrade  (Read 4984 times)

Amiga1000

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
Size of Sprite is issue after upgrade
« on: August 20, 2014, 10:05:19 AM »

Hi,
I recently inherited some code that uses NGUI and I am unfamiliar with NGUI.
There is an issue that is occurring after the upgrade from 2.7 to 3.6 with the size of a sprite.

I’ve looked through the upgrade videos,on-line  info and it looks like all the upgade changes for UISlicedSprite to UISprite have been previous done in the code.

The problem is with the sprite “Highlight” from the SciFi Atlas.  In the code the highlight sprite is adjusted to a 4:3 ratio and scaled larger or smaller depending on the user input.
Currently the sprite appears extremely large and is not visible in the game screen.  localScale does not appear to work for the sprite after the upgade. What is the correct way to solve this upgrade issue with sprite sizes so they appear and scale as they did in NGUI 2.7?  Below is the basic code that worked in 2.7.

public UISprite BoxObject;
//  Normalized box size (4 * boxScale = box width in pixels; 3 * boxScale = box height in pixels)
private float boxScale =17F;
 …
newScale = Vector3.one;
   newScale.x = Mathf.Clamp(boxScale * 4.0f, 68.0f, 400.0f);   //  4:3 ratio
   newScale.y = Mathf.Clamp(boxScale * 3.0f, 51.0f, 300.0f);
   boxObject.transform.localScale = newScale;

Thank you.


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Size of Sprite is issue after upgrade
« Reply #1 on: August 20, 2014, 05:47:08 PM »
Instead of setting the localScale, set UIWidget.width and UIWidget.height.

Amiga1000

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
Re: Size of Sprite is issue after upgrade
« Reply #2 on: August 21, 2014, 12:45:44 PM »
OK, thanks.
So in my example it would be setting the boxScale width and height to the newScale x and y

 public UISprite BoxObject;
//  Normalized box size (4 * boxScale = box width in pixels; 3 * boxScale = box height in pixels)
private float boxScale =17F;
 …
newScale = Vector3.one;
   newScale.x = Mathf.Clamp(boxScale * 4.0f, 68.0f, 400.0f);   //  4:3 ratio
   newScale.y = Mathf.Clamp(boxScale * 3.0f, 51.0f, 300.0f);
   boxObject.width =  (int)newScale.x;
   boxObject.height =  (int)newScale.y;

Correct?

Amiga1000

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
Re: Size of Sprite is issue after upgrade
« Reply #3 on: August 21, 2014, 12:59:14 PM »
Sorry, I meant to say:
So in my example it would be setting the boxObject width and height to the newScale x and y

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Size of Sprite is issue after upgrade
« Reply #4 on: August 22, 2014, 03:42:33 AM »
Yup.