Namespace: gui
Language: Lua
Type: Defold Lua
File: gui_ddf.proto
Source: engine/gamesys/proto/gamesys/gui_ddf.proto
GUI API documentation
Type: FUNCTION This is a callback-function, which is called by the engine when a gui component is finalized (destroyed). It can be used to e.g. take some last action, report the finalization to other game object instances or release user input focus (see release_input_focus). There is no use in starting any animations or similar from this function since the gui component is about to be destroyed.
Parameters
self (script_instance) - script instance used for storing stateExamples
function final(self)
-- report finalization
msg.post("my_friend_instance", "im_dead", {my_stats = self.some_value})
end
Type: PROPERTY The fonts used in the gui. The type of the property is hash. Key must be specified in options table.
Examples
How to set font using a script property (see resource.font)
go.property("title_latin", resource.font("/open_sans.font"))
go.property("title_cyrillic", resource.font("/open_sans_cyrillic.font"))
function init(self)
go.set("#gui", "fonts", self.title_cyrillic, {key = "title"})
end
Type: ENUM Adjust modes
Members
gui.ADJUST_FIT - fit adjust mode Adjust mode is used when the screen resolution differs from the project settings. The fit mode ensures that the entire node is visible in the adjusted gui scene.gui.ADJUST_STRETCH - stretch adjust mode Adjust mode is used when the screen resolution differs from the project settings. The stretch mode ensures that the node is displayed as is in the adjusted gui scene, which might scale it non-uniformally.gui.ADJUST_ZOOM - zoom adjust mode Adjust mode is used when the screen resolution differs from the project settings. The zoom mode ensures that the node fills its entire area and might make the node exceed it.Type: ENUM Anchor modes
Members
gui.ANCHOR_BOTTOM - bottom y-anchorgui.ANCHOR_LEFT - left x-anchorgui.ANCHOR_NONE - no anchorgui.ANCHOR_RIGHT - right x-anchorgui.ANCHOR_TOP - top y-anchorType: FUNCTION This starts an animation of a node property according to the specified parameters. If the node property is already being animated, that animation will be canceled and replaced by the new one. Note however that several different node properties can be animated simultaneously. Use gui.cancel_animations to stop the animation before it has completed. Composite properties of type vector3, vector4 or quaternion also expose their sub-components (x, y, z and w). You can address the components individually by suffixing the name with a dot ‘.’ and the name of the component. For instance, “position.x” (the position x coordinate) or “color.w” (the color alpha value). If a complete_function (Lua function) is specified, that function will be called when the animation has completed. By starting a new animation in that function, several animations can be sequenced together. See the examples below for more information.
Parameters
node (node) - node to animateproperty (string |
hash | gui.PROP) - property to animate; each gui.PROP member equals its corresponding property name string |
to (number |
vector3 | vector4 | quaternion) - target property value |
easing (gui.EASING | vector) - easing to use during animation.
Either specify one of the gui.EASING_* constants or provide a
vector with a custom curve. See the animation guide for more information.duration (number) - duration of the animation in seconds.delay (number) (optional) - delay before the animation starts in seconds.complete_function (fun(self:script_instance, node:node)) (optional) - function to call when the
animation has completedplayback (gui.PLAYBACK) (optional) - playback modeExamples
How to start a simple color animation, where the node fades in to white during 0.5 seconds:
gui.set_color(node, vmath.vector4(0, 0, 0, 0)) -- node is fully transparent
gui.animate(node, gui.PROP_COLOR, vmath.vector4(1, 1, 1, 1), gui.EASING_INOUTQUAD, 0.5) -- start animation
How to start a sequenced animation where the node fades in to white during 0.5 seconds, stays visible for 2 seconds and then fades out:
local function on_animation_done(self, node)
-- fade out node, but wait 2 seconds before the animation starts
gui.animate(node, gui.PROP_COLOR, vmath.vector4(0, 0, 0, 0), gui.EASING_OUTQUAD, 0.5, 2.0)
end
function init(self)
-- fetch the node we want to animate
local my_node = gui.get_node("my_node")
-- node is initially set to fully transparent
gui.set_color(my_node, vmath.vector4(0, 0, 0, 0))
-- animate the node immediately and call on_animation_done when the animation has completed
gui.animate(my_node, gui.PROP_COLOR, vmath.vector4(1, 1, 1, 1), gui.EASING_INOUTQUAD, 0.5, 0.0, on_animation_done)
end
How to animate a node’s y position using a crazy custom easing curve:
function init(self)
local values = { 0, 0, 0, 0, 0, 0, 0, 0,
1, 1, 1, 1, 1, 1, 1, 1,
0, 0, 0, 0, 0, 0, 0, 0,
1, 1, 1, 1, 1, 1, 1, 1,
0, 0, 0, 0, 0, 0, 0, 0,
1, 1, 1, 1, 1, 1, 1, 1,
0, 0, 0, 0, 0, 0, 0, 0,
1, 1, 1, 1, 1, 1, 1, 1 }
local vec = vmath.vector(values)
local node = gui.get_node("box")
gui.animate(node, "position.y", 100, vec, 4.0, 0, nil, gui.PLAYBACK_LOOP_PINGPONG)
end
Type: ENUM Blend modes
Members
gui.BLEND_ADD - additive blendinggui.BLEND_ADD_ALPHA - additive alpha blendinggui.BLEND_ALPHA - alpha blendinggui.BLEND_MULT - multiply blendinggui.BLEND_SCREEN - screen blendingType: FUNCTION If one or more animations of the specified node is currently running (started by gui.animate), they will immediately be canceled.
Parameters
node (node) - node that should have its animation canceledproperty (nil |
string | hash | gui.PROP) (optional) - optional property for which the animation should be canceled |
"position""rotation""euler""scale""color""outline""shadow""size""fill_angle" (pie)"inner_radius" (pie)"leading" (text)"tracking" (text)"slice9" (slice9)Examples
Start an animation of the position property of a node, then cancel parts of the animation:
local node = gui.get_node("my_node")
-- animate to new position
local pos = vmath.vector3(100, 100, 0)
gui.animate(node, "position", pos, go.EASING_LINEAR, 2)
...
-- cancel animation of the x component.
gui.cancel_animations(node, "position.x")
Cancels all property animations on a node in a single call:
local node = gui.get_node("my_node")
-- animate to new position and scale
gui.animate(node, "position", vmath.vector3(100, 100, 0), go.EASING_LINEAR, 5)
gui.animate(node, "scale", vmath.vector3(0.5), go.EASING_LINEAR, 5)
...
-- cancel positioning and scaling at once
gui.cancel_animations(node)
Type: FUNCTION Cancels any running flipbook animation on the specified node.
Parameters
node (node) - node cancel flipbook animation forExamples
local node = gui.get_node("anim_node")
gui.cancel_flipbook(node)
Type: ENUM Clipping modes
Members
gui.CLIPPING_MODE_NONE - clipping mode nonegui.CLIPPING_MODE_STENCIL - clipping mode stencilType: FUNCTION Make a clone instance of a node. The cloned node will be identical to the original node, except the id which is generated as the string “node” plus a sequential unsigned integer value. This function does not clone the supplied node’s children nodes. Use gui.clone_tree for that purpose.
Parameters
node (node) - node to cloneReturns
clone (node) - the cloned nodeType: FUNCTION Make a clone instance of a node and all its children. Use gui.clone to clone a node excluding its children.
Parameters
node (node) - root node to cloneReturns
clones (table<hash, node>) - a table mapping node ids to the corresponding cloned nodesType: FUNCTION Deletes the specified node. Any child nodes of the specified node will be recursively deleted.
Parameters
node (node) - node to deleteExamples
Delete a particular node and any child nodes it might have:
local node = gui.get_node("my_node")
gui.delete_node(node)
Type: FUNCTION Delete a dynamically created texture.
Parameters
texture (string |
hash) - texture id |
Examples
function init(self)
-- Create a texture.
if gui.new_texture("temp_tx", 10, 10, "rgb", string.rep('\0', 10 * 10 * 3)) then
-- Do something with the texture.
...
-- Delete the texture
gui.delete_texture("temp_tx")
end
end
Type: ENUM Easing curves
Members
gui.EASING_INBACK - in-backgui.EASING_INBOUNCE - in-bouncegui.EASING_INCIRC - in-circlicgui.EASING_INCUBIC - in-cubicgui.EASING_INELASTIC - in-elasticgui.EASING_INEXPO - in-exponentialgui.EASING_INOUTBACK - in-out-backgui.EASING_INOUTBOUNCE - in-out-bouncegui.EASING_INOUTCIRC - in-out-circlicgui.EASING_INOUTCUBIC - in-out-cubicgui.EASING_INOUTELASTIC - in-out-elasticgui.EASING_INOUTEXPO - in-out-exponentialgui.EASING_INOUTQUAD - in-out-quadraticgui.EASING_INOUTQUART - in-out-quarticgui.EASING_INOUTQUINT - in-out-quinticgui.EASING_INOUTSINE - in-out-sinegui.EASING_INQUAD - in-quadraticgui.EASING_INQUART - in-quarticgui.EASING_INQUINT - in-quinticgui.EASING_INSINE - in-sinegui.EASING_LINEAR - linear interpolationgui.EASING_OUTBACK - out-backgui.EASING_OUTBOUNCE - out-bouncegui.EASING_OUTCIRC - out-circlicgui.EASING_OUTCUBIC - out-cubicgui.EASING_OUTELASTIC - out-elasticgui.EASING_OUTEXPO - out-exponentialgui.EASING_OUTINBACK - out-in-backgui.EASING_OUTINBOUNCE - out-in-bouncegui.EASING_OUTINCIRC - out-in-circlicgui.EASING_OUTINCUBIC - out-in-cubicgui.EASING_OUTINELASTIC - out-in-elasticgui.EASING_OUTINEXPO - out-in-exponentialgui.EASING_OUTINQUAD - out-in-quadraticgui.EASING_OUTINQUART - out-in-quarticgui.EASING_OUTINQUINT - out-in-quinticgui.EASING_OUTINSINE - out-in-sinegui.EASING_OUTQUAD - out-quadraticgui.EASING_OUTQUART - out-quarticgui.EASING_OUTQUINT - out-quinticgui.EASING_OUTSINE - out-sineType: FUNCTION Instead of using specific getters such as gui.get_position or gui.get_scale, you can use gui.get instead and supply the property as a string or a hash. While this function is similar to go.get, there are a few more restrictions when operating in the gui namespace. Most notably, only these explicitly named properties are supported:
“position” “rotation” “euler” “scale” “color” “outline” “shadow” “size” “fill_angle” (pie) “inner_radius” (pie) “leading” (text) “tracking” (text) “slice9” (slice9)
The value returned will either be a vmath.vector4 or a single number, i.e getting the “position” property will return a vec4 while getting the “position.x” property will return a single value. You can also use this function to get material constants.
Parameters
node (node) - node to get the property forproperty (string |
hash | gui.PROP) - the property to retrieve |
options ({ index?:integer }) (optional) - optional options table (only applicable for material constants)index integer index into array property (1 based)Examples
Get properties on existing nodes:
local node = gui.get_node("my_box_node")
local node_position = gui.get(node, "position")
Type: FUNCTION Returns the adjust mode of a node. The adjust mode defines how the node will adjust itself to screen resolutions that differs from the one in the project settings.
Parameters
node (node) - node from which to get the adjust mode (node)Returns
adjust_mode (gui.ADJUST) - the current adjust modeType: FUNCTION gets the node alpha
Parameters
node (node) - node from which to get alphaReturns
alpha (number) - alphaType: FUNCTION Returns the blend mode of a node. Blend mode defines how the node will be blended with the background.
Parameters
node (node) - node from which to get the blend modeReturns
blend_mode (gui.BLEND) - blend modeType: FUNCTION If node is set as an inverted clipping node, it will clip anything inside as opposed to outside.
Parameters
node (node) - node from which to get the clipping inverted stateReturns
inverted (boolean) - true or falseType: FUNCTION Clipping mode defines how the node will clip it’s children nodes
Parameters
node (node) - node from which to get the clipping modeReturns
clipping_mode (gui.CLIPPING_MODE) - clipping modegui.CLIPPING_MODE_NONEgui.CLIPPING_MODE_STENCILType: FUNCTION If node is set as visible clipping node, it will be shown as well as clipping. Otherwise, it will only clip but not show visually.
Parameters
node (node) - node from which to get the clipping visibility stateReturns
visible (boolean) - true or falseType: FUNCTION Returns the color of the supplied node. The components of the returned vector4 contains the color channel values:
Component Color value
x Red value
y Green value
z Blue value
w Alpha value
Parameters
node (node) - node to get the color fromReturns
color (vector4) - node colorType: FUNCTION Returns the rotation of the supplied node. The rotation is expressed in degree Euler angles.
Parameters
node (node) - node to get the rotation fromReturns
rotation (vector3) - node rotationType: FUNCTION Returns the sector angle of a pie node.
Parameters
node (node) - node from which to get the fill angleReturns
angle (number) - sector angleType: FUNCTION Get node flipbook animation.
Parameters
node (node) - node to get flipbook animation fromReturns
animation (hash) - animation idType: FUNCTION This is only useful nodes with flipbook animations. Gets the normalized cursor of the flipbook animation on a node.
Parameters
node (node) - node to get the cursor for (node)Returns
cursor (number) - cursor valueType: FUNCTION This is only useful nodes with flipbook animations. Gets the playback rate of the flipbook animation on a node.
Parameters
node (node) - node to set the cursor forReturns
rate (number) - playback rateType: FUNCTION This is only useful for text nodes. The font must be mapped to the gui scene in the gui editor.
Parameters
node (node) - node from which to get the fontReturns
font (hash) - font idType: FUNCTION This is only useful for text nodes. The font must be mapped to the gui scene in the gui editor.
Parameters
font_name (hash |
string) - font of which to get the path hash |
Returns
hash (hash) - path hash to resourceExamples
Get the text metrics for a text
function init(self)
local node = gui.get_node("name")
local font_name = gui.get_font(node)
local font = gui.get_font_resource(font_name)
local metrics = resource.get_text_metrics(font, "The quick brown fox\n jumps over the lazy dog")
end
Type: FUNCTION Returns the scene height.
Returns
height (number) - scene heightType: FUNCTION Retrieves the id of the specified node.
Parameters
node (node) - the node to retrieve the id fromReturns
id (hash) - the id of the nodeExamples
Gets the id of a node:
local node = gui.get_node("my_node")
local id = gui.get_id(node)
print(id) --> hash: [my_node]
Type: FUNCTION Retrieve the index of the specified node among its siblings. The index defines the order in which a node appear in a GUI scene. Higher index means the node is drawn on top of lower indexed nodes.
Parameters
node (node) - the node to retrieve the id fromReturns
index (number) - the index of the nodeExamples
Compare the index order of two sibling nodes:
local node1 = gui.get_node("my_node_1")
local node2 = gui.get_node("my_node_2")
if gui.get_index(node1) < gui.get_index(node2) then
-- node1 is drawn below node2
else
-- node2 is drawn below node1
end
Type: FUNCTION gets the node inherit alpha state
Parameters
node (node) - node from which to get the inherit alpha stateReturns
inherit_alpha (boolean) - true or falseType: FUNCTION Returns the inner radius of a pie node. The radius is defined along the x-axis.
Parameters
node (node) - node from where to get the inner radiusReturns
radius (number) - inner radiusType: FUNCTION The layer must be mapped to the gui scene in the gui editor.
Parameters
node (node) - node from which to get the layerReturns
layer (hash) - layer idType: FUNCTION gets the scene current layout
Returns
layout (hash) - layout idType: FUNCTION Returns the sprites and links found in the text node’s current layout. Each object’s x and y identify its lower-left corner relative to the text node’s upper-left layout origin.
Parameters
node (node) - text node to inspectReturns
objects (gui.layout_object[]) - layout objects in source orderType: FUNCTION Returns a table mapping each layout id hash to a vector3(width, height, 0). For the default layout, the current scene resolution is returned. If a layout name is not present in the Display Profiles (or when no display profiles are assigned), the width/height pair is 0.
Returns
return (table<hash, vector3>) - layout_id_hash -> vmath.vector3(width, height, 0)Type: FUNCTION Returns the leading value for a text node.
Parameters
node (node) - node from where to get the leadingReturns
leading (number) - leading scaling value (default=1)Type: FUNCTION Returns whether a text node is in line-break mode or not. This is only useful for text nodes.
Parameters
node (node) - node from which to get the line-break forReturns
line_break (boolean) - true or falseType: FUNCTION Returns the material of a node. The material must be mapped to the gui scene in the gui editor.
Parameters
node (node) - node to get the material forReturns
materal (hash) - material idExamples
Getting the material for a node, and assign it to another node:
local node1 = gui.get_node("my_node")
local node2 = gui.get_node("other_node")
local node1_material = gui.get_material(node1)
gui.set_material(node2, node1_material)
Type: FUNCTION Retrieves the node with the specified id.
Parameters
id (string |
hash) - id of the node to retrieve |
Returns
instance (node) - a new node instanceExamples
Gets a node by id and change its color:
local node = gui.get_node("my_node")
local red = vmath.vector4(1.0, 0.0, 0.0, 1.0)
gui.set_color(node, red)
Type: FUNCTION Returns the outer bounds mode for a pie node.
Parameters
node (node) - node from where to get the outer bounds modeReturns
bounds_mode (gui.PIEBOUNDS) - the outer bounds mode of the pie nodeType: FUNCTION Returns the outline color of the supplied node. See gui.get_color for info how vectors encode color values.
Parameters
node (node) - node to get the outline color fromReturns
color (vector4) - outline colorType: FUNCTION Returns the parent node of the specified node. If the supplied node does not have a parent, nil is returned.
Parameters
node (node) - the node from which to retrieve its parentReturns
parent (node |
nil) - parent instance or nil |
Type: FUNCTION Get the paricle fx for a gui node
Parameters
node (node) - node to get particle fx forReturns
particlefx (hash) - particle fx idType: FUNCTION Returns the number of generated vertices around the perimeter of a pie node.
Parameters
node (node) - pie nodeReturns
vertices (number) - vertex countType: FUNCTION The pivot specifies how the node is drawn and rotated from its position.
Parameters
node (node) - node to get pivot fromReturns
pivot (gui.PIVOT) - pivot constantgui.PIVOT_CENTERgui.PIVOT_Ngui.PIVOT_NEgui.PIVOT_Egui.PIVOT_SEgui.PIVOT_Sgui.PIVOT_SWgui.PIVOT_Wgui.PIVOT_NWType: FUNCTION Returns the position of the supplied node.
Parameters
node (node) - node to get the position fromReturns
position (vector3) - node positionType: FUNCTION Returns the rotation of the supplied node. The rotation is expressed as a quaternion
Parameters
node (node) - node to get the rotation fromReturns
rotation (quaternion) - node rotationType: FUNCTION Returns the scale of the supplied node.
Parameters
node (node) - node to get the scale fromReturns
scale (vector3) - node scaleType: FUNCTION Returns the screen position of the supplied node. This function returns the calculated transformed position of the node, taking into account any parent node transforms.
Parameters
node (node) - node to get the screen position fromReturns
position (vector3) - node screen positionType: FUNCTION Returns the shadow color of the supplied node. See gui.get_color for info how vectors encode color values.
Parameters
node (node) - node to get the shadow color fromReturns
color (vector4) - node shadow colorType: FUNCTION Returns the size of the supplied node.
Parameters
node (node) - node to get the size fromReturns
size (vector3) - node sizeType: FUNCTION Returns the size of a node. The size mode defines how the node will adjust itself in size. Automatic size mode alters the node size based on the node’s content. Automatic size mode works for Box nodes and Pie nodes which will both adjust their size to match the assigned image. Particle fx and Text nodes will ignore any size mode setting.
Parameters
node (node) - node from which to get the size mode (node)Returns
size_mode (gui.SIZE_MODE) - the current size modeType: FUNCTION Returns the slice9 configuration values for the node.
Parameters
node (node) - node to manipulateReturns
values (vector4) - configuration valuesType: FUNCTION Returns the text value of a text node. This is only useful for text nodes.
Parameters
node (node) - node from which to get the textReturns
text (string) - text valueType: FUNCTION Returns the texture of a node. This is currently only useful for box or pie nodes. The texture must be mapped to the gui scene in the gui editor.
Parameters
node (node) - node to get texture fromReturns
texture (hash) - texture idType: FUNCTION Returns the tracking value of a text node.
Parameters
node (node) - node from where to get the trackingReturns
tracking (number) - tracking scaling number (default=0)Type: FUNCTION Get a node and all its children as a Lua table.
Parameters
node (node) - root node to get node tree fromReturns
clones (table<hash, node>) - a table mapping node ids to the corresponding nodesType: FUNCTION gets the node type
Parameters
node (node) - node from which to get the typeReturns
type (gui.TYPE) - typesubtype (number |
nil) - id of the custom type |
Type: FUNCTION Returns true if a node is visible and false if it’s not. Invisible nodes are not rendered.
Parameters
node (node) - node to queryReturns
visible (boolean) - whether the node is visible or notType: FUNCTION Returns the scene width.
Returns
width (number) - scene widthType: FUNCTION The x-anchor specifies how the node is moved when the game is run in a different resolution.
Parameters
node (node) - node to get x-anchor fromReturns
anchor (gui.ANCHOR) - anchor constantgui.ANCHOR_NONEgui.ANCHOR_LEFTgui.ANCHOR_RIGHTType: FUNCTION The y-anchor specifies how the node is moved when the game is run in a different resolution.
Parameters
node (node) - node to get y-anchor fromReturns
anchor (gui.ANCHOR) - anchor constantgui.ANCHOR_NONEgui.ANCHOR_TOPgui.ANCHOR_BOTTOMType: FUNCTION Hides the on-display touch keyboard on the device.
Type: FUNCTION Returns true if a node is enabled and false if it’s not. Disabled nodes are not rendered and animations acting on them are not evaluated.
Parameters
node (node) - node to queryrecursive (boolean) (optional) - check hierarchy recursivelyReturns
enabled (boolean) - whether the node is enabled or notType: ENUM Keyboard types
Members
gui.KEYBOARD_TYPE_DEFAULT - default keyboardgui.KEYBOARD_TYPE_EMAIL - email keyboardgui.KEYBOARD_TYPE_NUMBER_PAD - number input keyboardgui.KEYBOARD_TYPE_PASSWORD - password keyboardType: STRUCT Rich-text layout object
Members
type (string) - object type, currently link or spriteid (hash) - the object’s id attribute, or its generated layout object idtext_offset (integer) - zero-based UTF-32 offset in the visible texttext_length (integer) - visible UTF-32 text length covered by the objectx (number) - lower-left x-coordinate relative to the text node’s upper-left layout originy (number) - lower-left y-coordinate relative to the text node’s upper-left layout originwidth (number) - resolved object widthheight (number) - resolved object heightattributes (table<string, string>) - markup attributes keyed by nameType: FUNCTION Alters the ordering of the two supplied nodes by moving the first node above the second. If the second argument is nil the first node is moved to the top.
Parameters
node (node) - to movereference (node |
nil) - reference node above which the first node should be moved |
Type: FUNCTION Alters the ordering of the two supplied nodes by moving the first node below the second. If the second argument is nil the first node is moved to the bottom.
Parameters
node (node) - to movereference (node |
nil) - reference node below which the first node should be moved |
Type: FUNCTION Dynamically create a new box node.
Parameters
pos (vector3 |
vector4) - node position |
size (vector3) - node sizeReturns
node (node) - new box nodeType: FUNCTION Dynamically create a particle fx node.
Parameters
pos (vector3 |
vector4) - node position |
particlefx (hash |
string) - particle fx resource name |
Returns
node (node) - new particle fx nodeType: FUNCTION Dynamically create a new pie node.
Parameters
pos (vector3 |
vector4) - node position |
size (vector3) - node sizeReturns
node (node) - new pie nodeType: FUNCTION Dynamically create a new text node.
Parameters
pos (vector3 |
vector4) - node position |
text (string) - node textReturns
node (node) - new text nodeType: FUNCTION Dynamically create a new texture.
Parameters
texture_id (string |
hash) - texture id |
width (number) - texture widthheight (number) - texture heighttype (string |
image.TYPE) - texture type |
"rgb" or image.TYPE_RGB - RGB"rgba" or image.TYPE_RGBA - RGBA"l" or image.TYPE_LUMINANCE - LUMINANCE"astc" - ASTC compressed formatbuffer (string) - texture dataflip (boolean) - flip texture verticallyReturns
success (boolean) - texture creation was successfulcode (gui.RESULT |
nil) - one of the gui.RESULT_* codes if unsuccessful |
Examples
How to create a texture and apply it to a new box node:
function init(self)
local w = 200
local h = 300
-- A nice orange. String with the RGB values.
local orange = string.char(0xff) .. string.char(0x80) .. string.char(0x10)
-- Create the texture. Repeat the color string for each pixel.
local ok, reason = gui.new_texture("orange_tx", w, h, "rgb", string.rep(orange, w * h))
if ok then
-- Create a box node and apply the texture to it.
local n = gui.new_box_node(vmath.vector3(200, 200, 0), vmath.vector3(w, h, 0))
gui.set_texture(n, "orange_tx")
else
-- Could not create texture for some reason...
if reason == gui.RESULT_TEXTURE_ALREADY_EXISTS then
...
else
...
end
end
end
How to create a texture using .astc format
local path = "/assets/images/logo_4x4.astc"
local buffer = sys.load_resource(path)
local n = gui.new_box_node(pos, vmath.vector3(size, size, 0))
-- size is read from the .astc buffer
-- flip is not supported
gui.new_texture(path, 0, 0, "astc", buffer, false)
gui.set_texture(n, path)
Type: FUNCTION Tests whether a coordinate is within the bounding box of a node.
Parameters
node (node) - node to be tested for pickingx (number) - x-coordinate (see on_input )y (number) - y-coordinate (see on_input )Returns
pickable (boolean) - pick resultType: ENUM Pie bounds modes
Members
gui.PIEBOUNDS_ELLIPSE - elliptical pie node boundsgui.PIEBOUNDS_RECTANGLE - rectangular pie node boundsType: ENUM Pivot modes
Members
gui.PIVOT_CENTER - center pivotgui.PIVOT_E - east pivotgui.PIVOT_N - north pivotgui.PIVOT_NE - north-east pivotgui.PIVOT_NW - north-west pivotgui.PIVOT_S - south pivotgui.PIVOT_SE - south-east pivotgui.PIVOT_SW - south-west pivotgui.PIVOT_W - west pivotType: FUNCTION Play flipbook animation on a box or pie node. The current node texture must contain the animation. Use this function to set one-frame still images on the node.
Parameters
node (node) - node to set animation foranimation (string |
hash) - animation id |
complete_function (fun(self:script_instance, node:node)) (optional) - optional function to call when the animation has completedself:script_instanceThe current script instance.</dd>
node:nodeThe node that is animated.</dd> </dl>
play_properties (gui.play_properties) (optional) - optional playback propertiesExamples
Set the texture of a node to a flipbook animation from an atlas:
local function anim_callback(self, node)
-- Take action after animation has played.
end
function init(self)
-- Create a new node and set the texture to a flipbook animation
local node = gui.get_node("button_node")
gui.set_texture(node, "gui_sprites")
gui.play_flipbook(node, "animated_button")
end
Set the texture of a node to an image from an atlas:
-- Create a new node and set the texture to a "button.png" from atlas
local node = gui.get_node("button_node")
gui.set_texture(node, "gui_sprites")
gui.play_flipbook(node, "button")
Type: FUNCTION Plays the paricle fx for a gui node
Parameters
node (node) - node to play particle fx foremitter_state_function (fun(self:script_instance, node:node |
nil, emitter:hash, state:particlefx.EMITTER_STATE)) (optional) - optional callback function that will be called when an emitter attached to this particlefx changes state. |
Examples
How to play a particle fx when a gui node is created. The callback receives the gui node, the hash of the id of the emitter, and the new state of the emitter as particlefx.EMITTER_STATE_.
local function emitter_state_change(self, node, emitter, state)
if emitter == hash("exhaust") and state == particlefx.EMITTER_STATE_POSTSPAWN then
-- exhaust is done spawning particles...
end
end
function init(self)
gui.play_particlefx(gui.get_node("particlefx"), emitter_state_change)
end
Type: STRUCT GUI flipbook playback properties
Members
offset? (number) - Normalized initial animation cursor.playback_rate? (number) - Positive animation playback rate.Type: ENUM Playback modes
Members
gui.PLAYBACK_LOOP_BACKWARD - loop backwardgui.PLAYBACK_LOOP_FORWARD - loop forwardgui.PLAYBACK_LOOP_PINGPONG - ping pong loopgui.PLAYBACK_ONCE_BACKWARD - once backwardgui.PLAYBACK_ONCE_FORWARD - once forwardgui.PLAYBACK_ONCE_PINGPONG - once forward and then backwardType: ENUM GUI property names
Members
gui.PROP_COLOR - color propertygui.PROP_EULER - euler propertygui.PROP_FILL_ANGLE - fill_angle propertygui.PROP_INNER_RADIUS - inner_radius propertygui.PROP_LEADING - leading propertygui.PROP_OUTLINE - outline color propertygui.PROP_POSITION - position propertygui.PROP_ROTATION - rotation propertygui.PROP_SCALE - scale propertygui.PROP_SHADOW - shadow color propertygui.PROP_SIZE - size propertygui.PROP_SLICE9 - slice9 propertygui.PROP_TRACKING - tracking propertyType: FUNCTION Resets the input context of keyboard. This will clear marked text.
Type: FUNCTION Resets the node material to the material assigned in the gui scene.
Parameters
node (node) - node to reset the material forExamples
Resetting the material for a node:
local node = gui.get_node("my_node")
gui.reset_material(node)
Type: FUNCTION Resets all nodes in the current GUI scene to their initial state. The reset only applies to static node loaded from the scene. Nodes that are created dynamically from script are not affected.
Type: ENUM GUI results
Members
gui.RESULT_DATA_ERROR - data error The provided data is not in the expected format or is in some other way incorrect, for instance the image data provided to gui.new_texture().gui.RESULT_OUT_OF_RESOURCES - out of resource The system is out of resources, for instance when trying to create a new texture using gui.new_texture().gui.RESULT_TEXTURE_ALREADY_EXISTS - texture already exists The texture id already exists when trying to use gui.new_texture().Type: ENUM Safe-area modes
Members
gui.SAFE_AREA_BOTH - both sides safe area Safe area mode that applies insets on all edges.gui.SAFE_AREA_LONG - long side safe area Safe area mode that applies insets only on the long edges.gui.SAFE_AREA_NONE - no safe area Safe area mode that ignores safe area insets.gui.SAFE_AREA_SHORT - short side safe area Safe area mode that applies insets only on the short edges.Type: FUNCTION Converts a screen-space position to the local position value for the supplied node. The conversion takes the parent transform, anchors, adjust mode, and adjust reference into account.
Parameters
node (node) - node whose local position space should be usedscreen_position (vector3) - screen-space positionReturns
local_position (vector3) - local position value for the nodeExamples
Animate a node to the pressed pointer position:
function init(self)
msg.post(".", "acquire_input_focus")
self.marker = gui.get_node("marker")
end
function on_input(self, action_id, action)
if action_id == hash("touch") and action.pressed then
local screen_position = vmath.vector3(action.screen_x, action.screen_y, 0)
local target_position = gui.screen_to_local(self.marker, screen_position)
gui.animate(self.marker, gui.PROP_POSITION, target_position, gui.EASING_OUTQUAD, 0.2)
return true
end
end
Type: FUNCTION Instead of using specific setteres such as gui.set_position or gui.set_scale, you can use gui.set instead and supply the property as a string or a hash. While this function is similar to go.get and go.set, there are a few more restrictions when operating in the gui namespace. Most notably, only these named properties identifiers are supported:
“position” “rotation” “euler” “scale” “color” “outline” “shadow” “size” “fill_angle” (pie) “inner_radius” (pie) “leading” (text) “tracking” (text) “slice9” (slice9)
The value to set must either be a vmath.vector4, vmath.vector3, vmath.quat or a single number and depends on the property name you want to set. I.e when setting the “position” property, you need to use a vmath.vector4 and when setting a single component of the property, such as “position.x”, you need to use a single value. Note: When setting the rotation using the “rotation” property, you need to pass in a vmath.quat. This behaviour is different than from the gui.set_rotation function, the intention is to move new functionality closer to go namespace so that migrating between gui and go is easier. To set the rotation using degrees instead, use the “euler” property instead. The rotation and euler properties are linked, changing one of them will change the backing data of the other. Similar to go.set, you can also use gui.set for setting material constant values on a node. E.g if a material has specified a constant called tint in the .material file, you can use gui.set to set the value of that constant by calling gui.set(node, “tint”, vmath.vec4(1,0,0,1)), or gui.set(node, “matrix”, vmath.matrix4()) if the constant is a matrix. Arrays are also supported by gui.set - to set an array constant, you need to pass in an options table with the ‘index’ key set. If the material has a constant array called ‘tint_array’ specified in the material, you can use gui.set(node, “tint_array”, vmath.vec4(1,0,0,1), { index = 4}) to set the fourth array element to a different value.
Parameters
node (node |
url) - node to set the property for, or msg.url() to the gui itself |
property (string |
hash | gui.PROP) - the property to set |
value (number |
vector4 | vector3 | quaternion | nil) - the property to set. nil is only supported for removing runtime texture mappings with gui.set(msg.url(), "textures", nil, {key = ...}). |
options (gui.set_options) (optional) - optional material-constant optionsExamples
Updates the position property on an existing node:
local node = gui.get_node("my_box_node")
local node_position = gui.get(node, "position")
gui.set(node, "position.x", node_position.x + 128)
Updates the rotation property on an existing node:
local node = gui.get_node("my_box_node")
gui.set(node, "rotation", vmath.quat_rotation_z(math.rad(45)))
-- this is equivalent to:
gui.set(node, "euler.z", 45)
-- or using the entire vector:
gui.set(node, "euler", vmath.vector3(0,0,45))
-- or using the set_rotation
gui.set_rotation(node, vmath.vector3(0,0,45))
Sets various material constants for a node:
local node = gui.get_node("my_box_node")
gui.set(node, "tint", vmath.vector4(1,0,0,1))
-- matrix4 is also supported
gui.set(node, "light_matrix", vmath.matrix4())
-- update a constant in an array at position 4. the array is specified in the shader as:
-- uniform vec4 tint_array[4]; // lua is 1 based, shader is 0 based
gui.set(node, "tint_array", vmath.vector4(1,0,0,1), { index = 4 })
-- update a matrix constant in an array at position 4. the array is specified in the shader as:
-- uniform mat4 light_matrix_array[4];
gui.set(node, "light_matrix_array", vmath.matrix4(), { index = 4 })
-- update a sub-element in a constant
gui.set(node, "tint.x", 1)
-- update a sub-element in an array constant at position 4
gui.set(node, "tint_array.x", 1, {index = 4})
Set a named property
function on_message(self, message_id, message, sender)
if message_id == hash("set_font") then
gui.set(msg.url(), "fonts", message.font, {key = "my_font_name"})
gui.set_font(gui.get_node("text"), "my_font_name")
elseif message_id == hash("set_texture") then
gui.set(msg.url(), "textures", message.texture, {key = "my_texture"})
gui.set_texture(gui.get_node("box"), "my_texture")
gui.play_flipbook(gui.get_node("box"), "logo_256")
end
end
Remove a named runtime texture resource mapping:
local atlas_id = resource.create_atlas("/runtime.texturesetc", atlas_params)
gui.set(msg.url(), "textures", atlas_id, {key = "runtime_texture"})
gui.set_texture(gui.get_node("box"), "runtime_texture")
-- Later, remove the GUI mapping before releasing the atlas resource.
gui.set(msg.url(), "textures", nil, {key = "runtime_texture"})
resource.release(atlas_id)
Type: FUNCTION Sets the adjust mode on a node. The adjust mode defines how the node will adjust itself to screen resolutions that differs from the one in the project settings.
Parameters
node (node) - node to set adjust mode foradjust_mode (gui.ADJUST) - adjust mode to setType: FUNCTION sets the node alpha
Parameters
node (node) - node for which to set alphaalpha (number) - 0..1 alpha colorType: FUNCTION Set the blend mode of a node. Blend mode defines how the node will be blended with the background.
Parameters
node (node) - node to set blend mode forblend_mode (gui.BLEND) - blend mode to setType: FUNCTION If node is set as an inverted clipping node, it will clip anything inside as opposed to outside.
Parameters
node (node) - node to set clipping inverted state forinverted (boolean) - true or falseType: FUNCTION Clipping mode defines how the node will clip it’s children nodes
Parameters
node (node) - node to set clipping mode forclipping_mode (gui.CLIPPING_MODE) - clipping mode to setgui.CLIPPING_MODE_NONEgui.CLIPPING_MODE_STENCILType: FUNCTION If node is set as an visible clipping node, it will be shown as well as clipping. Otherwise, it will only clip but not show visually.
Parameters
node (node) - node to set clipping visibility forvisible (boolean) - true or falseType: FUNCTION Sets the color of the supplied node. The components of the supplied vector3 or vector4 should contain the color channel values:
Component Color value
x Red value
y Green value
z Blue value
w vector4 Alpha value
Parameters
node (node) - node to set the color forcolor (vector3 |
vector4) - new color |
Type: FUNCTION Sets a node to the disabled or enabled state. Disabled nodes are not rendered and animations acting on them are not evaluated.
Parameters
node (node) - node to be enabled/disabledenabled (boolean) - whether the node should be enabled or notType: FUNCTION Sets the rotation of the supplied node. The rotation is expressed in degree Euler angles.
Parameters
node (node) - node to set the rotation forrotation (vector3 |
vector4) - new rotation |
Type: FUNCTION Set the sector angle of a pie node.
Parameters
node (node) - node to set the fill angle forangle (number) - sector angleType: FUNCTION This is only useful nodes with flipbook animations. The cursor is normalized.
Parameters
node (node) - node to set the cursor forcursor (number) - cursor valueType: FUNCTION This is only useful nodes with flipbook animations. Sets the playback rate of the flipbook animation on a node. Must be positive.
Parameters
node (node) - node to set the cursor forplayback_rate (number) - playback rateType: FUNCTION This is only useful for text nodes. The font must be mapped to the gui scene in the gui editor.
Parameters
node (node) - node for which to set the fontfont (string |
hash) - font id |
Type: FUNCTION Set the id of the specicied node to a new value. Nodes created with the gui.new_*_node() functions get an empty id. This function allows you to give dynamically created nodes an id. No checking is done on the uniqueness of supplied ids. It is up to you to make sure you use unique ids.
Parameters
node (node) - node to set the id forid (string |
hash) - id to set |
Examples
Create a new node and set its id:
local pos = vmath.vector3(100, 100, 0)
local size = vmath.vector3(100, 100, 0)
local node = gui.new_box_node(pos, size)
gui.set_id(node, "my_new_node")
Type: FUNCTION sets the node inherit alpha state
Parameters
node (node) - node from which to set the inherit alpha stateinherit_alpha (boolean) - true or falseType: FUNCTION Sets the inner radius of a pie node. The radius is defined along the x-axis.
Parameters
node (node) - node to set the inner radius forradius (number) - inner radiusType: FUNCTION The layer must be mapped to the gui scene in the gui editor.
Parameters
node (node) - node for which to set the layerlayer (string |
hash) - layer id |
Type: FUNCTION Applies a named layout on the GUI scene. This re-applies per-layout node descriptors and, if a matching Display Profile exists, updates the scene resolution. Emits the “layout_changed” message to the scene script when the layout actually changes.
Parameters
layout (string |
hash) - the layout id to apply |
Returns
return (boolean) - true if the layout exists in the scene and was applied, false otherwiseType: FUNCTION Sets the leading value for a text node. This value is used to scale the line spacing of text.
Parameters
node (node) - node for which to set the leadingleading (number) - a scaling value for the line spacing (default=1)Type: FUNCTION Sets the line-break mode on a text node. This is only useful for text nodes.
Parameters
node (node) - node to set line-break forline_break (boolean) - true or falseType: FUNCTION Set the material on a node. The material must be mapped to the gui scene in the gui editor, and assigning a material is supported for all node types. To set the default material that is assigned to the gui scene node, use gui.reset_material(node_id) instead.
Parameters
node (node) - node to set material formaterial (string |
hash) - material id |
Examples
Assign an existing material to a node:
local node = gui.get_node("my_node")
gui.set_material(node, "my_material")
Type: STRUCT Generic GUI property options
Members
index? (integer) - One-based material-constant array index.key? (hash) - Internal property name.Type: FUNCTION Sets the outer bounds mode for a pie node.
Parameters
node (node) - node for which to set the outer bounds modebounds_mode (gui.PIEBOUNDS) - the outer bounds mode of the pie nodeType: FUNCTION Sets the outline color of the supplied node. See gui.set_color for info how vectors encode color values.
Parameters
node (node) - node to set the outline color forcolor (vector3 |
vector4) - new outline color |
Type: FUNCTION Sets the parent node of the specified node.
Parameters
node (node) - node for which to set its parentparent (node) (optional) - parent node to set, pass nil to remove parentkeep_scene_transform (boolean) (optional) - optional flag to make the scene position being perservedType: FUNCTION Set the paricle fx for a gui node
Parameters
node (node) - node to set particle fx forparticlefx (hash |
string) - particle fx id |
Type: FUNCTION Sets the number of generated vertices around the perimeter of a pie node.
Parameters
node (node) - pie nodevertices (number) - vertex countType: FUNCTION The pivot specifies how the node is drawn and rotated from its position.
Parameters
node (node) - node to set pivot forpivot (gui.PIVOT) - pivot constantgui.PIVOT_CENTERgui.PIVOT_Ngui.PIVOT_NEgui.PIVOT_Egui.PIVOT_SEgui.PIVOT_Sgui.PIVOT_SWgui.PIVOT_Wgui.PIVOT_NWType: FUNCTION Sets the position of the supplied node.
Parameters
node (node) - node to set the position forposition (vector3 |
vector4) - new position |
Type: FUNCTION Set the order number for the current GUI scene. The number dictates the sorting of the “gui” render predicate, in other words in which order the scene will be rendered in relation to other currently rendered GUI scenes. The number must be in the range 0 to 15.
Parameters
order (number) - rendering order (0-15)Type: FUNCTION Sets the rotation of the supplied node. The rotation is expressed as a quaternion
Parameters
node (node) - node to set the rotation forrotation (quaternion |
vector4) - new rotation |
Type: FUNCTION Sets how the safe area is applied to this gui scene.
Parameters
mode (gui.SAFE_AREA) - safe area modeType: FUNCTION Sets the scaling of the supplied node.
Parameters
node (node) - node to set the scale forscale (vector3 |
vector4) - new scale |
Type: FUNCTION Set the screen position to the supplied node
Parameters
node (node) - node to set the screen position toscreen_position (vector3) - screen positionType: FUNCTION Sets the shadow color of the supplied node. See gui.set_color for info how vectors encode color values.
Parameters
node (node) - node to set the shadow color forcolor (vector3 |
vector4) - new shadow color |
Type: FUNCTION Sets the size of the supplied node. You can only set size on nodes with size mode set to SIZE_MODE_MANUAL
Parameters
node (node) - node to set the size forsize (vector3 |
vector4) - new size |
Type: FUNCTION Sets the size mode of a node. The size mode defines how the node will adjust itself in size. Automatic size mode alters the node size based on the node’s content. Automatic size mode works for Box nodes and Pie nodes which will both adjust their size to match the assigned image. Particle fx and Text nodes will ignore any size mode setting.
Parameters
node (node) - node to set size mode forsize_mode (gui.SIZE_MODE) - size mode to setType: FUNCTION Set the slice9 configuration values for the node.
Parameters
node (node) - node to manipulatevalues (vector4) - new valuesType: FUNCTION Set the text value of a text node. This is only useful for text nodes.
Parameters
node (node) - node to set text fortext (string |
number) - text to set |
Type: FUNCTION Set the texture on a box or pie node. The texture must be mapped to the gui scene in the gui editor. The function points out which texture the node should render from. If the texture is an atlas, further information is needed to select which image/animation in the atlas to render. In such cases, use gui.play_flipbook() in addition to this function.
Parameters
node (node) - node to set texture fortexture (string |
hash) - texture id |
Examples
To set a texture (or animation) from an atlas:
local node = gui.get_node("box_node")
gui.set_texture(node, "my_atlas")
gui.play_flipbook(node, "image")
Set a dynamically created texture to a node. Note that there is only one texture image in this case so gui.set_texture() is sufficient.
local w = 200
local h = 300
-- A nice orange. String with the RGB values.
local orange = string.char(0xff) .. string.char(0x80) .. string.char(0x10)
-- Create the texture. Repeat the color string for each pixel.
if gui.new_texture("orange_tx", w, h, "rgb", string.rep(orange, w * h)) then
local node = gui.get_node("box_node")
gui.set_texture(node, "orange_tx")
end
Type: FUNCTION Set the texture buffer data for a dynamically created texture.
Parameters
texture (string |
hash) - texture id |
width (number) - texture widthheight (number) - texture heighttype (string |
image.TYPE) - texture type |
"rgb" or image.TYPE_RGB - RGB"rgba" or image.TYPE_RGBA - RGBA"l" or image.TYPE_LUMINANCE - LUMINANCE"astc" - ASTC compressed formatbuffer (string) - texture dataflip (boolean) - flip texture verticallyReturns
success (boolean) - setting the data was successfulExamples
function init(self)
local w = 200
local h = 300
-- Create a dynamic texture, all white.
if gui.new_texture("dynamic_tx", w, h, "rgb", string.rep(string.char(0xff), w * h * 3)) then
-- Create a box node and apply the texture to it.
local n = gui.new_box_node(vmath.vector3(200, 200, 0), vmath.vector3(w, h, 0))
gui.set_texture(n, "dynamic_tx")
...
-- Change the data in the texture to a nice orange.
local orange = string.char(0xff) .. string.char(0x80) .. string.char(0x10)
if gui.set_texture_data("dynamic_tx", w, h, "rgb", string.rep(orange, w * h)) then
-- Go on and to more stuff
...
end
else
-- Something went wrong
...
end
end
Type: FUNCTION Sets the tracking value of a text node. This value is used to adjust the vertical spacing of characters in the text.
Parameters
node (node) - node for which to set the trackingtracking (number) - a scaling number for the letter spacing (default=0)Type: FUNCTION Set if a node should be visible or not. Only visible nodes are rendered.
Parameters
node (node) - node to be visible or notvisible (boolean) - whether the node should be visible or notType: FUNCTION The x-anchor specifies how the node is moved when the game is run in a different resolution.
Parameters
node (node) - node to set x-anchor foranchor (gui.ANCHOR) - anchor constantgui.ANCHOR_NONEgui.ANCHOR_LEFTgui.ANCHOR_RIGHTType: FUNCTION The y-anchor specifies how the node is moved when the game is run in a different resolution.
Parameters
node (node) - node to set y-anchor foranchor (gui.ANCHOR) - anchor constantgui.ANCHOR_NONEgui.ANCHOR_TOPgui.ANCHOR_BOTTOMType: FUNCTION Shows the on-display touch keyboard. The specified type of keyboard is displayed if it is available on the device. This function is only available on iOS and Android. .
Parameters
type (gui.KEYBOARD_TYPE) - keyboard typeautoclose (boolean) - if the keyboard should automatically close when clicking outsideType: ENUM Size modes
Members
gui.SIZE_MODE_AUTO - automatic size mode The size of the node is determined by the currently assigned texture.gui.SIZE_MODE_MANUAL - manual size mode The size of the node is determined by the size set in the editor, the constructor or by gui.set_size()Type: FUNCTION Stops the particle fx for a gui node
Parameters
node (node) - node to stop particle fx foroptions (particlefx.stop_options) (optional) - options used when stopping the particle fxType: ENUM Node types
Members
gui.TYPE_BOX - box typegui.TYPE_CUSTOM - custom typegui.TYPE_PARTICLEFX - particlefx typegui.TYPE_PIE - pie typegui.TYPE_TEXT - text typeType: FUNCTION This is a callback-function, which is called by the engine when a gui component is initialized. It can be used to set the initial state of the script and gui scene.
Parameters
self (script_instance) - script instance used for storing stateExamples
function init(self)
-- set up useful data
self.my_value = 1
end
Type: MESSAGE This message is broadcast to every GUI component when a layout change has been initiated on device.
Parameters
id (hash) - the id of the layout the engine is changing toprevious_id (hash) - the id of the layout the engine is changing fromExamples
function on_message(self, message_id, message, sender)
if message_id == hash("layout_changed") and message.id == hash("Landscape") then
-- switching layout to "Landscape"...
...
end
end
Type: PROPERTY The main material (the default material assigned to a GUI) used when rendering the gui. The type of the property is hash.
Examples
How to set material using a script property (see resource.material)
go.property("desaturate_material", resource.material("/desaturate.material"))
function init(self)
go.set("#gui", "material", self.desaturate_material)
end
Type: PROPERTY The materials used when rendering the gui. The type of the property is hash. Key must be specified in options table.
Examples
How to change a named material resource using a script property from a script
go.property("my_material", resource.material("/my_material.material"))
function init(self)
-- this will update the "my_gui_material" entry in the GUI to use the material
-- specified in the "my_material" script property.
go.set("#gui", "materials", self.my_material, { key = "my_gui_material" })
end
Type: TYPEDEF An opaque handle to a node in the current GUI scene. Obtain a node with gui.get_node, create one with a gui.new_*_node function, or clone an existing node. A handle becomes invalid when its node is deleted.
Parameters
value (userdata) - GUI node handleExamples
local health_bar = gui.get_node("health_bar")
gui.set_color(health_bar, vmath.vector4(1, 0, 0, 1))
local marker = gui.new_box_node(vmath.vector3(100, 100, 0), vmath.vector3(16, 16, 0))
Type: FUNCTION This is a callback-function, which is called by the engine when user input is sent to the instance of the gui component. It can be used to take action on the input, e.g. modify the gui according to the input. For an instance to obtain user input, it must first acquire input focus through the message acquire_input_focus. Any instance that has obtained input will be put on top of an input stack. Input is sent to all listeners on the stack until the end of stack is reached, or a listener returns true to signal that it wants input to be consumed. See the documentation of acquire_input_focus for more information.
Parameters
self (script_instance) - script instance used for storing stateaction_id (hash |
nil) - id of the received input action, as mapped in the input_binding-file, or nil for mouse movement |
action (on_input.action) - input data for the actionReturns
consume (boolean |
nil) - optional boolean to signal if the input should be consumed (not passed on to others) or not, default is false |
Examples
function on_input(self, action_id, action)
-- check for input
if action_id == hash("my_action") then
-- take appropritate action
self.my_value = action.value
end
-- consume input
return true
end
Type: FUNCTION This is a callback-function, which is called by the engine whenever a message has been sent to the gui component. It can be used to take action on the message, e.g. update the gui or send a response back to the sender of the message. The message parameter is a table containing the message data. If the message is sent from the engine, the documentation of the message specifies which data is supplied. See the update function for examples on how to use this callback-function.
Parameters
self (script_instance) - script instance used for storing statemessage_id (hash) - id of the received messagemessage (table<any, any>) - a table containing the message datasender (url) - address of the senderType: FUNCTION This is a callback-function, which is called by the engine when the gui script is reloaded, e.g. from the editor. It can be used for live development, e.g. to tweak constants or set up the state properly for the script.
Parameters
self (script_instance) - script instance used for storing stateExamples
function on_reload(self)
-- restore some color (or similar)
gui.set_color(gui.get_node("my_node"), self.my_original_color)
end
Type: MESSAGE Sent to the GUI script when an interactive rich-text object is clicked.
Parameters
id (hash) - the object’s id attribute, or its generated layout object idtype (hash) - the layout object type, currently linksrc (string) - the application-defined target from the object’s src attributeType: MESSAGE Sent to the GUI script when the pointer enters an interactive rich-text object.
Parameters
id (hash) - the object’s id attribute, or its generated layout object idtype (hash) - the layout object type, currently linksrc (string) - the application-defined target from the object’s src attributeType: MESSAGE Sent to the GUI script when the pointer leaves an interactive rich-text object.
Parameters
id (hash) - the object’s id attribute, or its generated layout object idtype (hash) - the layout object type, currently linksrc (string) - the application-defined target from the object’s src attributeType: PROPERTY The textures used in the gui. The type of the property is hash. Key must be specified in options table.
Examples
How to set texture using a script property (see resource.atlas)
go.property("cards_red", resource.atlas("/cards_red.atlas"))
go.property("cards_blue", resource.atlas("/cards_blue.atlas"))
function init(self)
go.set("#gui", "textures", self.cards_red, {key = "cards"})
end
Type: FUNCTION This is a callback-function, which is called by the engine every frame to update the state of a gui component. It can be used to perform any kind of gui related tasks, e.g. animating nodes.
Parameters
self (script_instance) - script instance used for storing statedt (number) - the time-step of the frame updateExamples
This example demonstrates how to update a text node that displays game score in a counting fashion. It is assumed that the gui component receives messages from the game when a new score is to be shown.
function init(self)
-- fetch the score text node for later use (assumes it is called "score")
self.score_node = gui.get_node("score")
-- keep track of the current score counted up so far
self.current_score = 0
-- keep track of the target score we should count up to
self.target_score = 0
-- how fast we will update the score, in score/second
self.score_update_speed = 1
end
function update(self, dt)
-- check if target score is more than current score
if self.current_score self.target_score then
self.current_score = self.target_score
end
-- update the score text node
gui.set_text(self.score_node, "" .. math.floor(self.current_score))
end
end
function on_message(self, message_id, message, sender)
-- check the message
if message_id == hash("set_score") then
self.target_score = message.score
end
end