HUD: Improve readability
This commit is contained in:
parent
aa82729356
commit
a37d84524c
@ -8,24 +8,24 @@ root: ../../
|
|||||||
|
|
||||||
Heads Up Display (HUD) elements allow you to show text, images, and other graphical elements.
|
Heads Up Display (HUD) elements allow you to show text, images, and other graphical elements.
|
||||||
|
|
||||||
HUD doesn't accept user input. For that, you should use a [Formspec](formspecs.html).
|
The HUD doesn't accept user input. For that, you should use a [Formspec](formspecs.html).
|
||||||
|
|
||||||
* Basic Interface
|
* [Basic Interface](#basic-interface)
|
||||||
* Positioning
|
* [Positioning](#positioning)
|
||||||
* Text Elements
|
* [Text Elements](#text-elements)
|
||||||
* Image Elements
|
* [Image Elements](#image-elements)
|
||||||
* Other Elements
|
* [Other Elements](#other-elements)
|
||||||
|
|
||||||
## Basic Interface
|
## Basic Interface
|
||||||
|
|
||||||
HUD elements are created using a player object.
|
HUD elements are created using a player object.
|
||||||
You can get the player object from a username like this:
|
You can get the player object from a username:
|
||||||
|
|
||||||
{% highlight lua %}
|
{% highlight lua %}
|
||||||
local player = minetest.get_player_by_name("username")
|
local player = minetest.get_player_by_name("username")
|
||||||
{% endhighlight %}
|
{% endhighlight %}
|
||||||
|
|
||||||
Once you have the player object, you can create an element:
|
Once you have the player object, you can create a HUD element:
|
||||||
|
|
||||||
{% highlight lua %}
|
{% highlight lua %}
|
||||||
local idx = player:hud_add({
|
local idx = player:hud_add({
|
||||||
@ -37,13 +37,13 @@ local idx = player:hud_add({
|
|||||||
})
|
})
|
||||||
{% endhighlight %}
|
{% endhighlight %}
|
||||||
|
|
||||||
This attributes in the above table and what they do vary depending on
|
The attributes in the HUD element table and what they do vary depending on
|
||||||
the `hud_elem_type`.\\
|
the `hud_elem_type`.\\
|
||||||
A number is returned by the hud_add function which is needed to identify the HUD element
|
The `hud_add` function returns a number which is needed to identify the HUD element
|
||||||
at a later time, if you wanted to change or delete it.
|
if you wanted to change or delete it.
|
||||||
|
|
||||||
You can change an attribute after creating a HUD element, such as what the text
|
You can change an attribute after creating a HUD element. For example, you can change
|
||||||
says:
|
the text:
|
||||||
|
|
||||||
{% highlight lua %}
|
{% highlight lua %}
|
||||||
player:hud_change(idx, "text", "New Text")
|
player:hud_change(idx, "text", "New Text")
|
||||||
@ -57,38 +57,39 @@ player:hud_remove(idx)
|
|||||||
|
|
||||||
## Positioning
|
## Positioning
|
||||||
|
|
||||||
Screens come in different sizes, and HUD elements need to work well on all sizes.
|
Screens come in different sizes, and HUD elements need to work well on all screens.
|
||||||
You locate an element using a combination of a position and an offset.
|
You locate an element using a combination of a position and an offset.
|
||||||
|
|
||||||
The position is a co-ordinate between (0, 0) and (1, 1) which determines where,
|
The position is a co-ordinate between (0, 0) and (1, 1) which determines where,
|
||||||
relative to the screen width and height, the element goes.
|
relative to the screen width and height, the element is located.
|
||||||
For example, an element with a position of (0.5, 0.5) will be in the center of the screen.
|
For example, an element with a position of (0.5, 0.5) will be in the center of the screen.
|
||||||
|
|
||||||
The offset applies a pixel offset to the position.\\
|
The offset applies a pixel offset to the position.\\
|
||||||
An element with a position of (0, 0) and an offset of (10, 10) will end up at the screen
|
For example, an element with a position of (0, 0) and an offset of (10, 10) will be at the screen
|
||||||
co-ordinates (0 * width + 10, 0 * height + 10).
|
co-ordinates (0 * width + 10, 0 * height + 10).
|
||||||
|
|
||||||
Please note that offset scales to DPI and a user defined factor.
|
Please note that offset scales to DPI and a user defined factor.
|
||||||
|
|
||||||
## Text Elements
|
## Text Elements
|
||||||
|
|
||||||
A text element is the simplest form of a HUD element.\\
|
A text element is the simplest type of HUD element.\\
|
||||||
Here is our earlier example, but with comments to explain each part:
|
Here is the earlier example, but with comments to explain each part:
|
||||||
|
|
||||||
{% highlight lua %}
|
{% highlight lua %}
|
||||||
local idx = player:hud_add({
|
local idx = player:hud_add({
|
||||||
hud_elem_type = "text", -- This is a text element
|
hud_elem_type = "text", -- This is a text element
|
||||||
position = {x = 1, y = 0},
|
position = {x = 1, y = 0},
|
||||||
offset = {x=-100, y = 20},
|
offset = {x=-100, y = 20},
|
||||||
scale = {x = 100, y = 100}, -- Maximum size of text, crops off any out of these bounds
|
scale = {x = 100, y = 100}, -- Maximum size of text, text outside these bounds is cropped
|
||||||
text = "My Text" -- The actual text shown
|
text = "My Text" -- The actual text shown
|
||||||
})
|
})
|
||||||
{% endhighlight %}
|
{% endhighlight %}
|
||||||
|
|
||||||
### Colors
|
### Colors
|
||||||
|
|
||||||
You can apply colors to the text, using the `number` attribute.
|
Use the `number` attribute to apply colors to the text.
|
||||||
Colors are in [Hexadecimal form](http://www.colorpicker.com/).
|
Colors are in [Hexadecimal form](http://www.colorpicker.com/).
|
||||||
|
For example:
|
||||||
|
|
||||||
{% highlight lua %}
|
{% highlight lua %}
|
||||||
local idx = player:hud_add({
|
local idx = player:hud_add({
|
||||||
@ -103,13 +104,13 @@ local idx = player:hud_add({
|
|||||||
|
|
||||||
## Image Elements
|
## Image Elements
|
||||||
|
|
||||||
Displays an image on the HUD.
|
Image elements display an image on the HUD.
|
||||||
|
|
||||||
The X co-ordinate of the `scale` attribute is the scale of the image, with 1 being the original texture size.
|
The X co-ordinate of the `scale` attribute is the scale of the image, with 1 being the original texture size.
|
||||||
Negative values represent that percentage of the screen it should take; e.g. x=-100 means 100% (width).
|
Negative values represent the percentage of the screen the image should use. For example, x=-100 means 100% (width).
|
||||||
|
|
||||||
Use `text` to specify the name of the texture.
|
Use `text` to specify the name of the texture.
|
||||||
|
|
||||||
## Other Elements
|
## Other Elements
|
||||||
|
|
||||||
Have a look at [lua_api.txt]({{ page.root }}lua_api.html#hud-element-types) for a complete list of HUD elements.
|
Read [lua_api.txt]({{ page.root }}lua_api.html#hud-element-types) for a complete list of HUD elements.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user