Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by sdgd · Jan 26, 2013 at 12:29 AM · guiscreenmousepositioninvert

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

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
6
Best Answer

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image sdgd · Jan 26, 2013 at 04:34 AM 0
Share

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

avatar image
1

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).

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image sdgd · Jan 26, 2013 at 03:43 AM 0
Share

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;
     }
avatar image sdgd · Jan 26, 2013 at 03:46 AM 0
Share

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

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

11 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Make GUI elements disappear 3 Answers

GUI - Scale GUIs According to Resolution 6 Answers

How do I invert an input axis using Javascript? 1 Answer

Render Sprite on Screen at 3d game 0 Answers

How can I detect if non-GUI interaction is on the upper or lower portion of the screen? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges