- Home /
why is screen inverted (mousepos, GUI el) any fixes?
ok why is it inverted?
when I'm placing GUI elements top left is X0 Y0
when moving with my mouse position bottom left is X0 Y0
it gives me loads of headache I can go with either one preferable top left but
for doing correct stuff sometimes in code I have to
YPos = -10-IYPos-(ItemCount*20)+((Input.Mouseposition.y - Screen.height) * -1); // it's for moving buttons around GUI
and sometimes not I'd prefer that's always same
I was trying with project settings inputs but no invert seems to fix it
example:
void OnGUI() {
Vector2 gPos = new Vector2(10, 20);
GUI.BeginGroup(new Rect(0, 0, Screen.width, Screen.height));
Vector2 convertedGUIPos = GUIUtility.GUIToScreenPoint(gPos);
Debug.Log("GUI: " + gPos + " Screen: " + convertedGUIPos);
GUI.Label(new Rect(0,0,100,20),Input.mousePosition.x.ToString());
GUI.Label(new Rect(0,20,100,20),Input.mousePosition.y.ToString());
GUI.EndGroup();
}
labels are at top left while saying that 0,0 is bottom left
even if this page says it does it reverseGUIUtility.GUIToScreenPoint
also it doesn't matter for
Vector2 gPos = new Vector2(10, 20);
where it is before or after begin group
Answer by Eric5h5 · Jan 26, 2013 at 04:24 AM
The screen is not inverted. There are two pixel coordinate systems: screen coordinates and GUI coordinates. Screen is bottom-up, GUI is top-down. Do not use functions that return screen coordinates if you're working with GUI coordinates--Input.mousePosition is for screen coordinates, so in OnGUI use Event.current.mousePosition instead, since that uses GUI coordinates.
YYYYYYYEEEEEEEEYYYYYY this what I've been searching for :D atlasssst
there were many Q/A with (input.mouseposition - screen.hight) * -1
including you told many people that seems that event.mouseposition is new feature
Answer by Loius · Jan 26, 2013 at 03:05 AM
This is just a thing you have to deal with (or you can wrap one of the classes in your own automatic inverter; a mouse-position or Rect inverter wouldn't be too hard).
It's annoying, it's stupid, and it's easy to fix, but it will never be fixed in any language you ever work in unless you do (or find) the fix yourself.
Pixels are arranged from top-left to bottom-right because monitors work by drawing from the topleft to the bottomright, and programmers just went along with that. I like that idea.
I'm not sure who decided it or why, but at some point someone said 'Wait, the [whatever] coordinate system starts at the bottom left! We need to do that!" That was a silly idea.
And then they-everyone proceeded to continue using top-left based coordinates for pixels, while using bottom-left based coordinates for other things (like mouse position).
BAH I hate stupidity
I was just searching through unity hardcore and was interested why can't I change as when I change it flips back
tho I made backup file if I'd accidentally mess something up but it seems it backs it self up automatically
it's in:
c:\Program$$anonymous$$g\Unity\Data\PlaybackEngines\flashsupport\BuildTools\AS3API\UnityEngine\Rect.as
public function Constructor_Rect($source: Rect): Rect {
this.m_X$$anonymous$$in = $source.m_X$$anonymous$$in;
this.m_Y$$anonymous$$in = $source.m_Y$$anonymous$$in;
this.m_Width = $source.m_Width;
this.m_Height = $source.m_Height;
return this;
}
public static function $$anonymous$$in$$anonymous$$axRect_Single_Single_Single_Single($left: Number, $top: Number, $right: Number, $bottom: Number): Rect {
return cil2as_InstanceFromPool().Constructor_Single_Single_Single_Single($left, $bottom, $right - $left, $top - $bottom);
}
public function Set_Single_Single_Single_Single($left: Number, $top: Number, $width: Number, $height: Number): void {
this.m_X$$anonymous$$in = $left;
this.m_Y$$anonymous$$in = $top;
this.m_Width = $width;
this.m_Height = $height;
}
are you Equipped with any
automatic inverter; a mouse-position or Rect inverter?
and witchone do you think is most recommended I can adopt to top and bottom whatever