Showing posts with label GUI. Show all posts
Showing posts with label GUI. Show all posts

Sunday, 19 January 2014

Absolute and Relative Positions

Laying out Unity menus using GUITexture and GUIText has been a bit confusing.

I'm not entirely sure I understand it yet but the basics are that everything is relative to it's parent.
I've been trying to calculate absolute pixel positions and this has been difficult.  Rarely has anything ended up where it was intended.



It wasn't until I read the following post that it sunk in that Unity is trying to scale everything to fit the screen or viewport:
http://answers.unity3d.com/questions/292620/scale-gui-texture-to-current-screen-size.html

As far as I can tell Unity is designed to allow for any resolution on different screen sizes on different platforms.  It scales to fit the screen automatically.

If I am doing it manually and Unity is doing it automatically I end up with the wrong result.

I haven't worked it all out myself yet but it might give others reading this a head start if they try to work with the Unity methods rather than bypass them!



==

Follow-up:  Since writing the above I have become more confused.  If I try to save screen positions in the OnGUI() method to line up with the text or graphic positions on the screen and then process actions based on them in the Update() method I frequently find that the positions are no longer valid.

My results are not consistent.  At the moment if I want an input position to line up with text, like processing my own version of a mouse over event, my only reliable solution is to carry out all the processing in the OnGUI() method.

Odd, perhaps someone can tell me why.

Saturday, 14 December 2013

Texture Quality

My first hurdle with Unity was understanding texture importing and displaying them in 2D.

Unity is very scene based.  Many games and most tutorials put all the options within the player controller of the scene.  I find this very odd.

I wanted to start with a menu, the sort of thing virtually all commercial games have and using that menu select the game options and launch the desired level.

That was not too difficult.  What has delayed me for the best part of an hour is texture quality.  I wanted a good quality logo. 



I kept getting a horrid artefact ridden blur!



Every setting I tried with the texture type set to 'Texture' resulted in the same reduced image.  It turns out that I need to use the 'GUI' texture type with a format of 'Truecolor' to avoid the texture being compressed and resized when it is imported. 


You drag the texture in to any folder, as you do with most assets and then change the settings.  Remember to press 'Apply' to see your changes.



Those settings conveniently led me to the 'GUI Texture' and 'GUI Text' objects that are probably better for me to use to create my menus.