Guitext and Guitexture
1, Guitext
The concept of Anchor point (Anchor) I will not introduce. Such important concepts as Ngui and TOOKIT2D, as well as cocos2d, can be thought of as the origin of the image itself.
The Guitext object itself is also a support for setting anchor points, but only 9 options. Used to set the origin of the whole of the displayed text text.
Any object will have a transform component, and what is useful in the Guitext object is position. What does this position stand for?
An important formula:
The entire text text of the whole of its own coordinate origin on the window screen position:
POS (x, y) = (position.x*screen.width + pixeloffset.x, Position.y*screen.height + pixeloffset.y)
This Position represents the base of the entire text of the whole text of its own coordinate origin, position.x is a multiple of the width of the entire window screen, POSITION.Y is a multiple of the height of the entire window screen.
Note that the coordinate origin of the screen is the lower-left corner (0,0).
2, Guitexture
This is not an anchor point, the original point of the picture is in the lower left corner (0,0,).
An important formula:
The entire guitexture picture's overall self-coordinate origin is positioned on the window screen:
POS (x, y) = (position.x*screen.width +pixelinset.x, Position.y*screen.height +pixelinset.y)
This Position represents the base of the entire text of the whole text of its own coordinate origin, position.x is a multiple of the width of the entire window screen, POSITION.Y is a multiple of the height of the entire window screen.
Finally, we do this logic: as the next game to end the effect.
The logic of the object is this, Gameover is an empty object.
Bg_end is the big background to the end of the game.
Here are three text Guitext
And there is guitexture "this time to get points" picture.
and a button-shaped guitexture picture
In order for the entire logic not to deform, it is to let the front of the various small UI elements do the game end of the large background of the child objects. We let the child object and the parent object be relative to the Transform.position.x,y value (note), may think that I set the child object's transform.position.x.y all is 0, 0,. Note that the child objects inherit from the parent object. The same as the child object. So we can adjust the pixelinset.x,y of the sub-object to the appropriate position.
We record this value for the button fake picture. Such as: We write code to show the real button to use.
Write the following code to display this button:
Voidongui ()//Display button//
{
Gui.skin= Mygui;
if (GUI. Button (Newrect (screen.width*0.5f-26.3f,screen.height*0.5f+178.71f-67f,61f,67f), "", GUI.skin.GetStyle (" Continuebutton ")))
{
Application.loadlevel ("MainMenu");
}
}
One of the main things to note here is " draw the coordinate system of the GUI interface to the upper left corner of the screen as (0,0) point "
Position formula for button:
(Screen.width* (Child position.x+ parent position.x) + child Pixelinset.x's original value, screen.height* (child position.y+ parent POSITION.Y) + Absolute value of sub-pixelinset.y-sub-PixelInset.h)
The size of the game is generally the artwork provided by the original size.
Unity3d GUI element Interface coordinate system summary (with formula)