Support => NGUI 3 Support => Topic started by: Darkness on December 19, 2013, 10:04:22 AM
Title: Converting to Screen Coordinates
Post by: Darkness on December 19, 2013, 10:04:22 AM
This is something that I keep having trouble with. I can't get it right and I need some guidance. Once and for all what is the best way to convert to screen coordinates? I have been using....
pos = UIWidget.localcorners[3];
newPos = camera.WorldToScreenPoint(pos);
What needs to happen from here? Menu keeps popping up on the edge of the screen and not near the middle like it's supposed to. Any ideas on how I can get this fixed?
Title: Re: Converting to Screen Coordinates
Post by: ArenMook on December 19, 2013, 12:19:34 PM
Screen coordinates are not local coordinates used by widgets. Local coordinates are just that -- local (relative to parent).
Screen coordinates start in the corner of the screen.
Local coordinates start where the parent is positioned (in case of UIRoot it's the center of the screen).
In your code, you're taking local coordinates, then use WorldToScreenPoint to convert them. They're not world coordinates. Use UIWidget.worldCorners if you need world coorners.
Title: Re: Converting to Screen Coordinates
Post by: Darkness on December 19, 2013, 10:55:04 PM
All I want to do is print a tooltip on top of the icon offset by a couple of pixels. However, it won't work, because using it's local coordinates puts the tooltip on the opposite side of the screen. I looked at your code that uses the mouse position to put the tooltip up and it works since Input.mousePosition gives screen coordinates. That's what I want. So how do I get screen coordinates of my widget so that the tooltip will end up in the right place?
*EDIT* Thanks for the information. I decided to change something and it ended up working. I think I understand how to get coordinates properly now. Thanks a bunch, AM. Helpful as always. :)