Author Topic: Get UISprite actual size  (Read 1970 times)

elvess

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 44
    • View Profile
Get UISprite actual size
« on: April 10, 2014, 01:24:08 PM »
Hello. I  have UIRoot set to FixedSize and a UISrite inside with Dimension = 150, 150 in bottom left corner. I need to calcuate something like Screen.width - UISprite width (in pixels). Actually when I call UISprite.localSize.x  or UISprite.width its give me 150. But on different resolutions actual size in pixels is different. Is there a way to get actuall pixel size of UISprite on each resoution?

Thank You,
Paul

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Get UISprite actual size
« Reply #1 on: April 11, 2014, 07:06:13 AM »
The layout system can use relative coordinates as well as absolute. Pixels are absolute. Changing the anchor to "custom" will let you specify a 0-1 range relative value. Horizontally 0 means "left", and 1 means "right", while 0.5 is "center". Check the UIRect's documentation page for details.

Since the UIRoot is Fixed Size, your UI is in virtual pixels and you need to convert screen pixels to virtual pixels by taking UIRoot's pixelSizeAdjustment into consideration.

elvess

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 44
    • View Profile
Re: Get UISprite actual size
« Reply #2 on: April 11, 2014, 07:15:58 AM »
Thank U,
pixelSizeAdjustment is what I need.