Author Topic: Virtual coordinates  (Read 5051 times)

blacklabgames

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 3
    • View Profile
Virtual coordinates
« on: February 20, 2015, 10:20:41 PM »
Hi.
I'm using "Constrained" scaling, and I'm trying to move a widget from the centre of the screen to the top-left corner in code. Because the screen resolution can change, I think I need to work out the "virtual co-ordinates" of the top-left corner, but haven't been able to do that yet.

How do I get the virtual coordinates of the top-left corner of the screen?

Thanks.
Paul
Black Lab Games.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Virtual coordinates
« Reply #1 on: February 21, 2015, 08:28:23 AM »
Why don't you just anchor this widget to the top left corner? Then you don't need to do anything.

But, to answer your question... pixels * UIRoot.GetPixelSizeAdjustment(gameObject).

blacklabgames

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 3
    • View Profile
Re: Virtual coordinates
« Reply #2 on: February 22, 2015, 11:19:00 PM »
" move a widget from the centre of the screen to the top-left corner in code"

I guess that wasn't clear...I meant animate a widget over a number of frames. So it starts centred then moves smoothly to the top-left corner over a second. The numerous aspect ratios mean that the widget finishes in the incorrect position in a lot of cases is I use a constant value or a Unity animation.

In the example "pixels * UIRoot.GetPixelSizeAdjustment(gameObject)", what is the range for "pixels" to achieve the above?  [0..Screen.width]?  [0..1]?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Virtual coordinates
« Reply #3 on: February 24, 2015, 11:13:05 AM »
Depends on what you're trying to animate to. if you want to move it from the exact center to exact top-left, then it would be Screen.width * 0.5, Screen.height * 0.5.

If you anchor another game object in the top left corner, then you could just tween to its position instead, without any need for math.