Author Topic: Screen position of an pivot  (Read 5544 times)

wom

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 34
    • View Profile
Screen position of an pivot
« on: December 14, 2013, 05:02:40 AM »
I'm trying to use NGUI and Vectrosity together.  I want to draw lines relative the the position of an NGUI widget.
I think the question is more general than that though - how to figure out the screen coordinates of the pivot of a given NGUI widget.

This code here gets me sort of close, but not quite:
  1.    
  2. panelAnchor = new Vector2(
  3.     screenCenter.x + graphPanel.transform.localPosition.x,
  4.     screenCenter.y + graphPanel.transform.localPosition.y);
  5.  

Screen center is the middle of the screen as calculated with Screen.height and Screen.width.
graphPanel is my NGUI widget (just an object with a UISprite on it, not a real UIPanel).
Vectrosity has been set up to use the NGUI UI camera.
My NGUI UIRoot is set to FixedSize scaling style with a manual height of 768.

I'm still on NGUI 3.0.6 (keen to upgrade to get the proper panel dragging and resizing, but I was hoping to get this working first).

The code above almost seems to work, but only when my game view is larger than the aspect ratio I've got set (iPad2, 1024x768). 
When the game view is scaled down (or I imagane, up) so that the height is not 768, the number I'm trying to calculate is off a bit.

Any idea how I can do this?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Screen position of an pivot
« Reply #1 on: December 14, 2013, 12:46:21 PM »
UIWidget.worldCorners gives you world-space coordinates viewed from the UI's camera. To convert to screen coordinates, use cam.WorldToScreen.