Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: blacklabgames on February 20, 2015, 10:20:41 PM

Title: Virtual coordinates
Post by: blacklabgames 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.
Title: Re: Virtual coordinates
Post by: ArenMook 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).
Title: Re: Virtual coordinates
Post by: blacklabgames 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]?
Title: Re: Virtual coordinates
Post by: ArenMook 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.