Gui

GUI core hooks, functions, messages, properties and constants for creation and manipulation of GUI nodes. The "gui" namespace is accessible only from gui scripts.

Namespace: gui
Include: #include <>
CONSTANTS
gui.ADJUST_FIT fit adjust mode
gui.ADJUST_STRETCH stretch adjust mode
gui.ADJUST_ZOOM zoom adjust mode
gui.ANCHOR_BOTTOM bottom y-anchor
gui.ANCHOR_LEFT left x-anchor
gui.ANCHOR_NONE no anchor
gui.ANCHOR_RIGHT right x-anchor
gui.ANCHOR_TOP top y-anchor
gui.BLEND_ADD additive blending
gui.BLEND_ADD_ALPHA additive alpha blending
gui.BLEND_ALPHA alpha blending
gui.BLEND_MULT multiply blending
gui.BLEND_SCREEN screen blending
gui.CLIPPING_MODE_NONE clipping mode none
gui.CLIPPING_MODE_STENCIL clipping mode stencil
gui.EASING_INBACK in-back
gui.EASING_INBOUNCE in-bounce
gui.EASING_INCIRC in-circlic
gui.EASING_INCUBIC in-cubic
gui.EASING_INELASTIC in-elastic
gui.EASING_INEXPO in-exponential
gui.EASING_INOUTBACK in-out-back
gui.EASING_INOUTBOUNCE in-out-bounce
gui.EASING_INOUTCIRC in-out-circlic
gui.EASING_INOUTCUBIC in-out-cubic
gui.EASING_INOUTELASTIC in-out-elastic
gui.EASING_INOUTEXPO in-out-exponential
gui.EASING_INOUTQUAD in-out-quadratic
gui.EASING_INOUTQUART in-out-quartic
gui.EASING_INOUTQUINT in-out-quintic
gui.EASING_INOUTSINE in-out-sine
gui.EASING_INQUAD in-quadratic
gui.EASING_INQUART in-quartic
gui.EASING_INQUINT in-quintic
gui.EASING_INSINE in-sine
gui.EASING_LINEAR linear interpolation
gui.EASING_OUTBACK out-back
gui.EASING_OUTBOUNCE out-bounce
gui.EASING_OUTCIRC out-circlic
gui.EASING_OUTCUBIC out-cubic
gui.EASING_OUTELASTIC out-elastic
gui.EASING_OUTEXPO out-exponential
gui.EASING_OUTINBACK out-in-back
gui.EASING_OUTINBOUNCE out-in-bounce
gui.EASING_OUTINCIRC out-in-circlic
gui.EASING_OUTINCUBIC out-in-cubic
gui.EASING_OUTINELASTIC out-in-elastic
gui.EASING_OUTINEXPO out-in-exponential
gui.EASING_OUTINQUAD out-in-quadratic
gui.EASING_OUTINQUART out-in-quartic
gui.EASING_OUTINQUINT out-in-quintic
gui.EASING_OUTINSINE out-in-sine
gui.EASING_OUTQUAD out-quadratic
gui.EASING_OUTQUART out-quartic
gui.EASING_OUTQUINT out-quintic
gui.EASING_OUTSINE out-sine
gui.KEYBOARD_TYPE_DEFAULT default keyboard
gui.KEYBOARD_TYPE_EMAIL email keyboard
gui.KEYBOARD_TYPE_NUMBER_PAD number input keyboard
gui.KEYBOARD_TYPE_PASSWORD password keyboard
gui.PIEBOUNDS_ELLIPSE elliptical pie node bounds
gui.PIEBOUNDS_RECTANGLE rectangular pie node bounds
gui.PIVOT_CENTER center pivot
gui.PIVOT_E east pivot
gui.PIVOT_N north pivot
gui.PIVOT_NE north-east pivot
gui.PIVOT_NW north-west pivot
gui.PIVOT_S south pivot
gui.PIVOT_SE south-east pivot
gui.PIVOT_SW south-west pivot
gui.PIVOT_W west pivot
gui.PLAYBACK_LOOP_BACKWARD loop backward
gui.PLAYBACK_LOOP_FORWARD loop forward
gui.PLAYBACK_LOOP_PINGPONG ping pong loop
gui.PLAYBACK_ONCE_BACKWARD once backward
gui.PLAYBACK_ONCE_FORWARD once forward
gui.PLAYBACK_ONCE_PINGPONG once forward and then backward
gui.PROP_COLOR color property
gui.PROP_EULER euler property
gui.PROP_FILL_ANGLE fill_angle property
gui.PROP_INNER_RADIUS inner_radius property
gui.PROP_LEADING leading property
gui.PROP_OUTLINE outline color property
gui.PROP_POSITION position property
gui.PROP_ROTATION rotation property
gui.PROP_SCALE scale property
gui.PROP_SHADOW shadow color property
gui.PROP_SIZE size property
gui.PROP_SLICE9 slice9 property
gui.PROP_TRACKING tracking property
gui.RESULT_DATA_ERROR data error
gui.RESULT_OUT_OF_RESOURCES out of resource
gui.RESULT_TEXTURE_ALREADY_EXISTS texture already exists
gui.SIZE_MODE_AUTO automatic size mode
gui.SIZE_MODE_MANUAL manual size mode
gui.TYPE_BOX box type
gui.TYPE_CUSTOM custom type
gui.TYPE_PARTICLEFX particlefx type
gui.TYPE_PIE pie type
gui.TYPE_TEXT text type
MESSAGES
layout_changed reports a layout change
PROPERTIES
fonts hash gui fonts
material hash gui material
materials hash gui materials
textures hash gui textures
FUNCTIONS
void final(object self) called when a gui component is finalized
void gui.animate(node node, stringconstant property, numbervector3vector4quaternion to, constantvector easing, number duration, number [delay], function(self, node) [complete_function], constant [playback]) animates a node property
void gui.cancel_animation(node node, stringconstant property) cancels an ongoing animation
void gui.cancel_flipbook(node node) cancel a node flipbook animation
node gui.clone(node node) clone a node
table gui.clone_tree(node node) clone a node including its children
void gui.delete_node(node node) deletes a node
void gui.delete_texture(stringhash texture) delete texture
void gui.get(node node, stringhashconstant property, table [options]) gets the named property of a specified gui node
constant gui.get_adjust_mode(node node) gets the node adjust mode
number gui.get_alpha(node node) gets the node alpha
constant gui.get_blend_mode(node node) gets the node blend mode
boolean gui.get_clipping_inverted(node node) gets node clipping inverted state
constant gui.get_clipping_mode(node node) gets the node clipping mode
boolean gui.get_clipping_visible(node node) gets node clipping visibility state
vector4 gui.get_color(node node) gets the node color
vector3 gui.get_euler(node node) gets the node rotation
number gui.get_fill_angle(node node) gets the angle for the filled pie sector
hash gui.get_flipbook(node node) gets the node flipbook animation
number gui.get_flipbook_cursor(node node) gets the normalized cursor of the animation on a node with flipbook animation
number gui.get_flipbook_playback_rate(node node) gets the playback rate of the flipbook animation on a node
hash gui.get_font(node node) gets the node font
hash gui.get_font_resource(hashstring font_name) gets the node font resource
number gui.get_height() gets the scene height
hash gui.get_id(node node) gets the id of the specified node
number gui.get_index(node node) gets the index of the specified node
boolean gui.get_inherit_alpha(node node) gets the node inherit alpha state
number gui.get_inner_radius(node node) gets the pie inner radius
hash gui.get_layer(node node) gets the node layer
hash gui.get_layout() gets the scene current layout
number gui.get_leading(node node) gets the leading of the text node
boolean gui.get_line_break(node node) get line-break mode
hash gui.get_material(node node) gets the assigned node material
node gui.get_node(stringhash id) gets the node with the specified id
constant gui.get_outer_bounds(node node) gets the pie outer bounds mode
vector4 gui.get_outline(node node) gets the node outline color
nil gui.get_parent(node node) gets the parent of the specified node
hash gui.get_particlefx(node node) Gets a particle fx
number gui.get_perimeter_vertices(node node) gets the number of generated vertices around the perimeter
constant gui.get_pivot(node node) gets the pivot of a node
vector3 gui.get_position(node node) gets the node position
quaternion gui.get_rotation(node node) gets the node rotation
vector3 gui.get_scale(node node) gets the node scale
vector3 gui.get_screen_position(node node) gets the node screen position
vector4 gui.get_shadow(node node) gets the node shadow color
vector3 gui.get_size(node node) gets the node size
constant gui.get_size_mode(node node) gets the node size mode
vector4 gui.get_slice9(node node) get the slice9 values for the node
string gui.get_text(node node) gets the node text
hash gui.get_texture(node node) gets node texture
number gui.get_tracking(node node) gets the tracking of the text node
table gui.get_tree(node node) get a node including its children
nil gui.get_type(node node) gets the node type
boolean gui.get_visible(node node) returns if a node is visible or not
number gui.get_width() gets the scene width
constant gui.get_xanchor(node node) gets the x-anchor of a node
constant gui.get_yanchor(node node) gets the y-anchor of a node
void gui.hide_keyboard() hides on-display keyboard if available
boolean gui.is_enabled(node node, boolean [recursive]) returns if a node is enabled or not
void gui.move_above(node node, nodenil reference) moves the first node above the second
void gui.move_below(node node, nodenil reference) moves the first node below the second
node gui.new_box_node(vector3vector4 pos, vector3 size) creates a new box node
node gui.new_particlefx_node(vector3vector4 pos, hashstring particlefx) creates a new particle fx node
node gui.new_pie_node(vector3vector4 pos, vector3 size) creates a new pie node
node gui.new_text_node(vector3vector4 pos, string text) creates a new text node
number gui.new_texture(stringhash texture_id, number width, number height, stringconstant type, string buffer, boolean flip) create new texture
boolean gui.pick_node(node node, number x, number y) determines if the node is pickable by the supplied coordinates
void gui.play_flipbook(node node, stringhash animation, function(self, node) [complete_function], table [play_properties]) play node flipbook animation
void gui.play_particlefx(node node, function(self, node, emitter, state) [emitter_state_function]) Plays a particle fx
void gui.reset_keyboard() resets on-display keyboard if available
void gui.reset_material(node node) resets the node material
void gui.reset_nodes() resets all nodes to initial state
vector3 gui.screen_to_local(node node, vector3 screen_position) convert screen position to the local node position
void gui.set(node node, stringhashconstant property, numbervector4vector3quat value, table [options]) sets the named property of a specified gui node
void gui.set_adjust_mode(node node, constant adjust_mode) sets node adjust mode
void gui.set_alpha(node node, number alpha) sets the node alpha
void gui.set_blend_mode(node node, constant blend_mode) sets node blend mode
void gui.set_clipping_inverted(node node, boolean inverted) sets node clipping inversion
void gui.set_clipping_mode(node node, constant clipping_mode) sets node clipping mode state
void gui.set_clipping_visible(node node, boolean visible) sets node clipping visibility
void gui.set_color(node node, vector3vector4 color) sets the node color
void gui.set_enabled(node node, boolean enabled) enables/disables a node
void gui.set_euler(node node, vector3vector4 rotation) sets the node rotation
void gui.set_fill_angle(node node, number angle) sets the angle for the filled pie sector
void gui.set_flipbook_cursor(node node, number cursor) sets the normalized cursor of the animation on a node with flipbook animation
void gui.set_flipbook_playback_rate(node node, number playback_rate) sets the playback rate of the flipbook animation on a node
void gui.set_font(node node, stringhash font) sets the node font
void gui.set_id(node node, stringhash id) sets the id of the specified node
void gui.set_inherit_alpha(node node, boolean inherit_alpha) sets the node inherit alpha state
void gui.set_inner_radius(node node, number radius) sets the pie inner radius
void gui.set_layer(node node, stringhash layer) sets the node layer
void gui.set_leading(node node, number leading) sets the leading of the text node
void gui.set_line_break(node node, boolean line_break) set line-break mode
void gui.set_material(node node, stringhash material) sets the node material
void gui.set_outer_bounds(node node, constant bounds_mode) sets the pie node outer bounds mode
void gui.set_outline(node node, vector3vector4 color) sets the node outline color
void gui.set_parent(node node, node [parent], boolean [keep_scene_transform]) sets the parent of the node
void gui.set_particlefx(node node, hashstring particlefx) Sets a particle fx
void gui.set_perimeter_vertices(node node, number vertices) sets the number of generated vertices around the perimeter
void gui.set_pivot(node node, constant pivot) sets the pivot of a node
void gui.set_position(node node, vector3vector4 position) sets the node position
void gui.set_render_order(number order) sets the render ordering for the current GUI scene
void gui.set_rotation(node node, quaternionvector4 rotation) sets the node rotation
void gui.set_scale(node node, vector3vector4 scale) sets the node scale
void gui.set_screen_position(node node, vector3 screen_position) sets screen position to the node
void gui.set_shadow(node node, vector3vector4 color) sets the node shadow color
void gui.set_size(node node, vector3vector4 size) sets the node size
void gui.set_size_mode(node node, constant size_mode) sets node size mode
void gui.set_slice9(node node, vector4 values) set the slice9 configuration for the node
void gui.set_text(node node, stringnumber text) sets the node text
void gui.set_texture(node node, stringhash texture) sets the node texture
boolean gui.set_texture_data(stringhash texture, number width, number height, stringconstant type, string buffer, boolean flip) set the buffer data for a texture
void gui.set_tracking(node node, number tracking) sets the tracking of the text node
void gui.set_visible(node node, boolean visible) set visibility for a node
void gui.set_xanchor(node node, constant anchor) sets the x-anchor of a node
void gui.set_yanchor(node node, constant anchor) sets the y-anchor of a node
void gui.show_keyboard(constant type, boolean autoclose) shows the on-display keyboard if available
void gui.stop_particlefx(node node, table [options]) Stops a particle fx
void init(object self) called when a gui component is initialized
nil on_input(object self, hash action_id, table action) called when user input is received
void on_message(object self, hash message_id, table message) called when a message has been sent to the gui component
void on_reload(object self) called when the gui script is reloaded
void update(object self, number dt) called every frame to update the gui component

Functions

final

void final(object self)

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

object self reference to the script state to be used for storing data

EXAMPLES

function final(self)
    -- report finalization
    msg.post("my_friend_instance", "im_dead", {my_stats = self.some_value})
end

gui.animate

void gui.animate(node node, stringconstant property, numbervector3vector4quaternion to, constantvector easing, number duration, number [delay], function(self, node) [complete_function], constant [playback])

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_animation 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 animate
string property property to animate
  • "position"
  • "rotation"
  • "euler"
  • "scale"
  • "color"
  • "outline"
  • "shadow"
  • "size"
  • "fill_angle" (pie)
  • "inner_radius" (pie)
  • "leading" (text)
  • "tracking" (text)
  • "slice9" (slice9)
The following property constants are defined equaling the corresponding property string names.
  • gui.PROP_POSITION
  • gui.PROP_ROTATION
  • gui.PROP_EULER
  • gui.PROP_SCALE
  • gui.PROP_COLOR
  • gui.PROP_OUTLINE
  • gui.PROP_SHADOW
  • gui.PROP_SIZE
  • gui.PROP_FILL_ANGLE
  • gui.PROP_INNER_RADIUS
  • gui.PROP_LEADING
  • gui.PROP_TRACKING
  • gui.PROP_SLICE9
constant property property to animate
  • "position"
  • "rotation"
  • "euler"
  • "scale"
  • "color"
  • "outline"
  • "shadow"
  • "size"
  • "fill_angle" (pie)
  • "inner_radius" (pie)
  • "leading" (text)
  • "tracking" (text)
  • "slice9" (slice9)
The following property constants are defined equaling the corresponding property string names.
  • gui.PROP_POSITION
  • gui.PROP_ROTATION
  • gui.PROP_EULER
  • gui.PROP_SCALE
  • gui.PROP_COLOR
  • gui.PROP_OUTLINE
  • gui.PROP_SHADOW
  • gui.PROP_SIZE
  • gui.PROP_FILL_ANGLE
  • gui.PROP_INNER_RADIUS
  • gui.PROP_LEADING
  • gui.PROP_TRACKING
  • gui.PROP_SLICE9
number to target property valuevector3 to target property valuevector4 to target property valuequaternion to target property value
constant easing 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.vector easing 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.
number duration duration of the animation in seconds.
number [delay] delay before the animation starts in seconds.
function(self, node) [complete_function] function to call when the animation has completed
constant [playback] playback mode
  • gui.PLAYBACK_ONCE_FORWARD
  • gui.PLAYBACK_ONCE_BACKWARD
  • gui.PLAYBACK_ONCE_PINGPONG
  • gui.PLAYBACK_LOOP_FORWARD
  • gui.PLAYBACK_LOOP_BACKWARD
  • gui.PLAYBACK_LOOP_PINGPONG

EXAMPLES

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

gui.cancel_animation

void gui.cancel_animation(node node, stringconstant property)

If an animation of the specified node is currently running (started by gui.animate), it will immediately be canceled.

PARAMETERS

node node node that should have its animation canceled
string property 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)
constant property 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_animation(node, "position.x")

gui.cancel_flipbook

void gui.cancel_flipbook(node node)

Cancels any running flipbook animation on the specified node.

PARAMETERS

node node node cancel flipbook animation for

EXAMPLES

local node = gui.get_node("anim_node")
gui.cancel_flipbook(node)

gui.clone

node gui.clone(node node)

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 clone

RETURNS

node the cloned node

gui.clone_tree

table gui.clone_tree(node node)

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 clone

RETURNS

table a table mapping node ids to the corresponding cloned nodes

gui.delete_node

void gui.delete_node(node node)

Deletes the specified node. Any child nodes of the specified node will be recursively deleted.

PARAMETERS

node node node to delete

EXAMPLES

Delete a particular node and any child nodes it might have:
local node = gui.get_node("my_node")
gui.delete_node(node)

gui.delete_texture

void gui.delete_texture(stringhash texture)

Delete a dynamically created texture.

PARAMETERS

string texture texture idhash texture 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

gui.get

void gui.get(node node, stringhashconstant property, table [options])

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 for
string property the property to retrievehash property the property to retrieveconstant property the property to retrieve
table [options] 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")

gui.get_adjust_mode

constant gui.get_adjust_mode(node node)

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

constant the current adjust mode
  • gui.ADJUST_FIT
  • gui.ADJUST_ZOOM
  • gui.ADJUST_STRETCH

gui.get_alpha

number gui.get_alpha(node node)

gets the node alpha

PARAMETERS

node node node from which to get alpha

RETURNS

number alpha

gui.get_blend_mode

constant gui.get_blend_mode(node node)

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 mode

RETURNS

constant blend mode
  • gui.BLEND_ALPHA
  • gui.BLEND_ADD
  • gui.BLEND_ADD_ALPHA
  • gui.BLEND_MULT
  • gui.BLEND_SCREEN

gui.get_clipping_inverted

boolean gui.get_clipping_inverted(node node)

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 state

RETURNS

boolean true or false

gui.get_clipping_mode

constant gui.get_clipping_mode(node node)

Clipping mode defines how the node will clip it's children nodes

PARAMETERS

node node node from which to get the clipping mode

RETURNS

constant clipping mode
  • gui.CLIPPING_MODE_NONE
  • gui.CLIPPING_MODE_STENCIL

gui.get_clipping_visible

boolean gui.get_clipping_visible(node node)

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 state

RETURNS

boolean true or false

gui.get_color

vector4 gui.get_color(node node)

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 from

RETURNS

vector4 node color

gui.get_euler

vector3 gui.get_euler(node node)

Returns the rotation of the supplied node. The rotation is expressed in degree Euler angles.

PARAMETERS

node node node to get the rotation from

RETURNS

vector3 node rotation

gui.get_fill_angle

number gui.get_fill_angle(node node)

Returns the sector angle of a pie node.

PARAMETERS

node node node from which to get the fill angle

RETURNS

number sector angle

gui.get_flipbook

hash gui.get_flipbook(node node)

Get node flipbook animation.

PARAMETERS

node node node to get flipbook animation from

RETURNS

hash animation id

gui.get_flipbook_cursor

number gui.get_flipbook_cursor(node node)

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

number cursor value

gui.get_flipbook_playback_rate

number gui.get_flipbook_playback_rate(node node)

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 for

RETURNS

number playback rate

gui.get_font

hash gui.get_font(node node)

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 font

RETURNS

hash font id

gui.get_font_resource

hash gui.get_font_resource(hashstring font_name)

This is only useful for text nodes. The font must be mapped to the gui scene in the gui editor.

PARAMETERS

hash font_name font of which to get the path hashstring font_name font of which to get the path hash

RETURNS

hash path hash to resource

EXAMPLES

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

gui.get_height

number gui.get_height()

Returns the scene height.

PARAMETERS

RETURNS

number scene height

gui.get_id

hash gui.get_id(node node)

Retrieves the id of the specified node.

PARAMETERS

node node the node to retrieve the id from

RETURNS

hash the id of the node

EXAMPLES

Gets the id of a node:
local node = gui.get_node("my_node")

local id = gui.get_id(node)
print(id) --> hash: [my_node]

gui.get_index

number gui.get_index(node node)

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 from

RETURNS

number the index of the node

EXAMPLES

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

gui.get_inherit_alpha

boolean gui.get_inherit_alpha(node node)

gets the node inherit alpha state

PARAMETERS

node node node from which to get the inherit alpha state

RETURNS

boolean true or false

gui.get_inner_radius

number gui.get_inner_radius(node node)

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 radius

RETURNS

number inner radius

gui.get_layer

hash gui.get_layer(node node)

The layer must be mapped to the gui scene in the gui editor.

PARAMETERS

node node node from which to get the layer

RETURNS

hash layer id

gui.get_layout

hash gui.get_layout()

gets the scene current layout

PARAMETERS

RETURNS

hash layout id

gui.get_leading

number gui.get_leading(node node)

Returns the leading value for a text node.

PARAMETERS

node node node from where to get the leading

RETURNS

number leading scaling value (default=1)

gui.get_line_break

boolean gui.get_line_break(node node)

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 for

RETURNS

boolean true or false

gui.get_material

hash gui.get_material(node node)

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 for

RETURNS

hash material id

EXAMPLES

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)

gui.get_node

node gui.get_node(stringhash id)

Retrieves the node with the specified id.

PARAMETERS

string id id of the node to retrievehash id id of the node to retrieve

RETURNS

node a new node instance

EXAMPLES

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)

gui.get_outer_bounds

constant gui.get_outer_bounds(node node)

Returns the outer bounds mode for a pie node.

PARAMETERS

node node node from where to get the outer bounds mode

RETURNS

constant the outer bounds mode of the pie node:
  • gui.PIEBOUNDS_RECTANGLE
  • gui.PIEBOUNDS_ELLIPSE

gui.get_outline

vector4 gui.get_outline(node node)

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 from

RETURNS

vector4 outline color

gui.get_parent

nil gui.get_parent(node node)

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 parent

RETURNS

node parent instance or nil
nil parent instance or nil

gui.get_particlefx

hash gui.get_particlefx(node node)

Get the paricle fx for a gui node

PARAMETERS

node node node to get particle fx for

RETURNS

hash particle fx id

gui.get_perimeter_vertices

number gui.get_perimeter_vertices(node node)

Returns the number of generated vertices around the perimeter of a pie node.

PARAMETERS

node node pie node

RETURNS

number vertex count

gui.get_pivot

constant gui.get_pivot(node node)

The pivot specifies how the node is drawn and rotated from its position.

PARAMETERS

node node node to get pivot from

RETURNS

constant pivot constant
  • gui.PIVOT_CENTER
  • gui.PIVOT_N
  • gui.PIVOT_NE
  • gui.PIVOT_E
  • gui.PIVOT_SE
  • gui.PIVOT_S
  • gui.PIVOT_SW
  • gui.PIVOT_W
  • gui.PIVOT_NW

gui.get_position

vector3 gui.get_position(node node)

Returns the position of the supplied node.

PARAMETERS

node node node to get the position from

RETURNS

vector3 node position

gui.get_rotation

quaternion gui.get_rotation(node node)

Returns the rotation of the supplied node. The rotation is expressed as a quaternion

PARAMETERS

node node node to get the rotation from

RETURNS

quaternion node rotation

gui.get_scale

vector3 gui.get_scale(node node)

Returns the scale of the supplied node.

PARAMETERS

node node node to get the scale from

RETURNS

vector3 node scale

gui.get_screen_position

vector3 gui.get_screen_position(node node)

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 from

RETURNS

vector3 node screen position

gui.get_shadow

vector4 gui.get_shadow(node node)

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 from

RETURNS

vector4 node shadow color

gui.get_size

vector3 gui.get_size(node node)

Returns the size of the supplied node.

PARAMETERS

node node node to get the size from

RETURNS

vector3 node size

gui.get_size_mode

constant gui.get_size_mode(node node)

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

constant the current size mode
  • gui.SIZE_MODE_MANUAL
  • gui.SIZE_MODE_AUTO

gui.get_slice9

vector4 gui.get_slice9(node node)

Returns the slice9 configuration values for the node.

PARAMETERS

node node node to manipulate

RETURNS

vector4 configuration values

gui.get_text

string gui.get_text(node node)

Returns the text value of a text node. This is only useful for text nodes.

PARAMETERS

node node node from which to get the text

RETURNS

string text value

gui.get_texture

hash gui.get_texture(node node)

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 from

RETURNS

hash texture id

gui.get_tracking

number gui.get_tracking(node node)

Returns the tracking value of a text node.

PARAMETERS

node node node from where to get the tracking

RETURNS

number tracking scaling number (default=0)

gui.get_tree

table gui.get_tree(node node)

Get a node and all its children as a Lua table.

PARAMETERS

node node root node to get node tree from

RETURNS

table a table mapping node ids to the corresponding nodes

gui.get_type

nil gui.get_type(node node)

gets the node type

PARAMETERS

node node node from which to get the type

RETURNS

constant type
  • gui.TYPE_BOX
  • gui.TYPE_TEXT
  • gui.TYPE_PIE
  • gui.TYPE_PARTICLEFX
  • gui.TYPE_CUSTOM
integer id of the custom type
nil id of the custom type

gui.get_visible

boolean gui.get_visible(node node)

Returns true if a node is visible and false if it's not. Invisible nodes are not rendered.

PARAMETERS

node node node to query

RETURNS

boolean whether the node is visible or not

gui.get_width

number gui.get_width()

Returns the scene width.

PARAMETERS

RETURNS

number scene width

gui.get_xanchor

constant gui.get_xanchor(node node)

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 from

RETURNS

constant anchor constant
  • gui.ANCHOR_NONE
  • gui.ANCHOR_LEFT
  • gui.ANCHOR_RIGHT

gui.get_yanchor

constant gui.get_yanchor(node node)

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 from

RETURNS

constant anchor constant
  • gui.ANCHOR_NONE
  • gui.ANCHOR_TOP
  • gui.ANCHOR_BOTTOM

gui.hide_keyboard

void gui.hide_keyboard()

Hides the on-display touch keyboard on the device.

PARAMETERS


gui.is_enabled

boolean gui.is_enabled(node node, boolean [recursive])

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 query
boolean [recursive] check hierarchy recursively

RETURNS

boolean whether the node is enabled or not

gui.move_above

void gui.move_above(node node, nodenil reference)

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 move
node reference reference node above which the first node should be movednil reference reference node above which the first node should be moved

gui.move_below

void gui.move_below(node node, nodenil reference)

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 move
node reference reference node below which the first node should be movednil reference reference node below which the first node should be moved

gui.new_box_node

node gui.new_box_node(vector3vector4 pos, vector3 size)

Dynamically create a new box node.

PARAMETERS

vector3 pos node positionvector4 pos node position
vector3 size node size

RETURNS

node new box node

gui.new_particlefx_node

node gui.new_particlefx_node(vector3vector4 pos, hashstring particlefx)

Dynamically create a particle fx node.

PARAMETERS

vector3 pos node positionvector4 pos node position
hash particlefx particle fx resource namestring particlefx particle fx resource name

RETURNS

node new particle fx node

gui.new_pie_node

node gui.new_pie_node(vector3vector4 pos, vector3 size)

Dynamically create a new pie node.

PARAMETERS

vector3 pos node positionvector4 pos node position
vector3 size node size

RETURNS

node new pie node

gui.new_text_node

node gui.new_text_node(vector3vector4 pos, string text)

Dynamically create a new text node.

PARAMETERS

vector3 pos node positionvector4 pos node position
string text node text

RETURNS

node new text node

gui.new_texture

number gui.new_texture(stringhash texture_id, number width, number height, stringconstant type, string buffer, boolean flip)

Dynamically create a new texture.

PARAMETERS

string texture_id texture idhash texture_id texture id
number width texture width
number height texture height
string type texture type
  • "rgb" - RGB
  • "rgba" - RGBA
  • "l" - LUMINANCE
constant type texture type
  • "rgb" - RGB
  • "rgba" - RGBA
  • "l" - LUMINANCE
string buffer texture data
boolean flip flip texture vertically

RETURNS

boolean texture creation was successful
number 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

gui.pick_node

boolean gui.pick_node(node node, number x, number y)

Tests whether a coordinate is within the bounding box of a node.

PARAMETERS

node node node to be tested for picking
number x x-coordinate (see on_input )
number y y-coordinate (see on_input )

RETURNS

boolean pick result

gui.play_flipbook

void gui.play_flipbook(node node, stringhash animation, function(self, node) [complete_function], table [play_properties])

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 for
string animation animation idhash animation animation id
function(self, node) [complete_function] optional function to call when the animation has completed
self
object The current object.
node
node The node that is animated.
table [play_properties] optional table with properties
offset
number The normalized initial value of the animation cursor when the animation starts playing
playback_rate
number The rate with which the animation will be played. Must be positive

EXAMPLES

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

gui.play_particlefx

void gui.play_particlefx(node node, function(self, node, emitter, state) [emitter_state_function])

Plays the paricle fx for a gui node

PARAMETERS

node node node to play particle fx for
function(self, node, emitter, state) [emitter_state_function] optional callback function that will be called when an emitter attached to this particlefx changes state.
self
object The current object
node
hash The particle fx node, or nil if the node was deleted
emitter
hash The id of the emitter
state
constant the new state of the emitter:
  • particlefx.EMITTER_STATE_SLEEPING
  • particlefx.EMITTER_STATE_PRESPAWN
  • particlefx.EMITTER_STATE_SPAWNING
  • particlefx.EMITTER_STATE_POSTSPAWN

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

gui.reset_keyboard

void gui.reset_keyboard()

Resets the input context of keyboard. This will clear marked text.

PARAMETERS


gui.reset_material

void gui.reset_material(node node)

Resets the node material to the material assigned in the gui scene.

PARAMETERS

node node node to reset the material for

EXAMPLES

Resetting the material for a node:
local node = gui.get_node("my_node")
gui.reset_material(node)

gui.reset_nodes

void gui.reset_nodes()

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.

PARAMETERS


gui.screen_to_local

vector3 gui.screen_to_local(node node, vector3 screen_position)

Convert the screen position to the local position of supplied node

PARAMETERS

node node node used for getting local transformation matrix
vector3 screen_position screen position

RETURNS

vector3 local position

gui.set

void gui.set(node node, stringhashconstant property, numbervector4vector3quat value, table [options])

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 node to set the property for
string property the property to sethash property the property to setconstant property the property to set
number value the property to setvector4 value the property to setvector3 value the property to setquat value the property to set
table [options] optional options table (only applicable for material constants) - index integer index into array property (1 based)

EXAMPLES

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

gui.set_adjust_mode

void gui.set_adjust_mode(node node, constant adjust_mode)

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 for
constant adjust_mode adjust mode to set
  • gui.ADJUST_FIT
  • gui.ADJUST_ZOOM
  • gui.ADJUST_STRETCH

gui.set_alpha

void gui.set_alpha(node node, number alpha)

sets the node alpha

PARAMETERS

node node node for which to set alpha
number alpha 0..1 alpha color

gui.set_blend_mode

void gui.set_blend_mode(node node, constant blend_mode)

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 for
constant blend_mode blend mode to set
  • gui.BLEND_ALPHA
  • gui.BLEND_ADD
  • gui.BLEND_ADD_ALPHA
  • gui.BLEND_MULT
  • gui.BLEND_SCREEN

gui.set_clipping_inverted

void gui.set_clipping_inverted(node node, boolean inverted)

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 for
boolean inverted true or false

gui.set_clipping_mode

void gui.set_clipping_mode(node node, constant clipping_mode)

Clipping mode defines how the node will clip it's children nodes

PARAMETERS

node node node to set clipping mode for
constant clipping_mode clipping mode to set
  • gui.CLIPPING_MODE_NONE
  • gui.CLIPPING_MODE_STENCIL

gui.set_clipping_visible

void gui.set_clipping_visible(node node, boolean visible)

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 for
boolean visible true or false

gui.set_color

void gui.set_color(node node, vector3vector4 color)

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 for
vector3 color new colorvector4 color new color

gui.set_enabled

void gui.set_enabled(node node, boolean enabled)

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/disabled
boolean enabled whether the node should be enabled or not

gui.set_euler

void gui.set_euler(node node, vector3vector4 rotation)

Sets the rotation of the supplied node. The rotation is expressed in degree Euler angles.

PARAMETERS

node node node to set the rotation for
vector3 rotation new rotationvector4 rotation new rotation

gui.set_fill_angle

void gui.set_fill_angle(node node, number angle)

Set the sector angle of a pie node.

PARAMETERS

node node node to set the fill angle for
number angle sector angle

gui.set_flipbook_cursor

void gui.set_flipbook_cursor(node node, number cursor)

This is only useful nodes with flipbook animations. The cursor is normalized.

PARAMETERS

node node node to set the cursor for
number cursor cursor value

gui.set_flipbook_playback_rate

void gui.set_flipbook_playback_rate(node node, number playback_rate)

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 for
number playback_rate playback rate

gui.set_font

void gui.set_font(node node, stringhash font)

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 font
string font font idhash font font id

gui.set_id

void gui.set_id(node node, stringhash id)

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 for
string id id to sethash id 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")

gui.set_inherit_alpha

void gui.set_inherit_alpha(node node, boolean inherit_alpha)

sets the node inherit alpha state

PARAMETERS

node node node from which to set the inherit alpha state
boolean inherit_alpha true or false

gui.set_inner_radius

void gui.set_inner_radius(node node, number radius)

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 for
number radius inner radius

gui.set_layer

void gui.set_layer(node node, stringhash layer)

The layer must be mapped to the gui scene in the gui editor.

PARAMETERS

node node node for which to set the layer
string layer layer idhash layer layer id

gui.set_leading

void gui.set_leading(node node, number leading)

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 leading
number leading a scaling value for the line spacing (default=1)

gui.set_line_break

void gui.set_line_break(node node, boolean line_break)

Sets the line-break mode on a text node. This is only useful for text nodes.

PARAMETERS

node node node to set line-break for
boolean line_break true or false

gui.set_material

void gui.set_material(node node, stringhash material)

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 for
string material material idhash material material id

EXAMPLES

Assign an existing material to a node:
local node = gui.get_node("my_node")
gui.set_material(node, "my_material")

gui.set_outer_bounds

void gui.set_outer_bounds(node node, constant bounds_mode)

Sets the outer bounds mode for a pie node.

PARAMETERS

node node node for which to set the outer bounds mode
constant bounds_mode the outer bounds mode of the pie node:
  • gui.PIEBOUNDS_RECTANGLE
  • gui.PIEBOUNDS_ELLIPSE

gui.set_outline

void gui.set_outline(node node, vector3vector4 color)

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 for
vector3 color new outline colorvector4 color new outline color

gui.set_parent

void gui.set_parent(node node, node [parent], boolean [keep_scene_transform])

Sets the parent node of the specified node.

PARAMETERS

node node node for which to set its parent
node [parent] parent node to set, pass nil to remove parent
boolean [keep_scene_transform] optional flag to make the scene position being perserved

gui.set_particlefx

void gui.set_particlefx(node node, hashstring particlefx)

Set the paricle fx for a gui node

PARAMETERS

node node node to set particle fx for
hash particlefx particle fx idstring particlefx particle fx id

gui.set_perimeter_vertices

void gui.set_perimeter_vertices(node node, number vertices)

Sets the number of generated vertices around the perimeter of a pie node.

PARAMETERS

node node pie node
number vertices vertex count

gui.set_pivot

void gui.set_pivot(node node, constant pivot)

The pivot specifies how the node is drawn and rotated from its position.

PARAMETERS

node node node to set pivot for
constant pivot pivot constant
  • gui.PIVOT_CENTER
  • gui.PIVOT_N
  • gui.PIVOT_NE
  • gui.PIVOT_E
  • gui.PIVOT_SE
  • gui.PIVOT_S
  • gui.PIVOT_SW
  • gui.PIVOT_W
  • gui.PIVOT_NW

gui.set_position

void gui.set_position(node node, vector3vector4 position)

Sets the position of the supplied node.

PARAMETERS

node node node to set the position for
vector3 position new positionvector4 position new position

gui.set_render_order

void gui.set_render_order(number order)

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

number order rendering order (0-15)

gui.set_rotation

void gui.set_rotation(node node, quaternionvector4 rotation)

Sets the rotation of the supplied node. The rotation is expressed as a quaternion

PARAMETERS

node node node to set the rotation for
quaternion rotation new rotationvector4 rotation new rotation

gui.set_scale

void gui.set_scale(node node, vector3vector4 scale)

Sets the scaling of the supplied node.

PARAMETERS

node node node to set the scale for
vector3 scale new scalevector4 scale new scale

gui.set_screen_position

void gui.set_screen_position(node node, vector3 screen_position)

Set the screen position to the supplied node

PARAMETERS

node node node to set the screen position to
vector3 screen_position screen position

gui.set_shadow

void gui.set_shadow(node node, vector3vector4 color)

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 for
vector3 color new shadow colorvector4 color new shadow color

gui.set_size

void gui.set_size(node node, vector3vector4 size)

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 for
vector3 size new sizevector4 size new size

gui.set_size_mode

void gui.set_size_mode(node node, constant size_mode)

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 for
constant size_mode size mode to set
  • gui.SIZE_MODE_MANUAL
  • gui.SIZE_MODE_AUTO

gui.set_slice9

void gui.set_slice9(node node, vector4 values)

Set the slice9 configuration values for the node.

PARAMETERS

node node node to manipulate
vector4 values new values

gui.set_text

void gui.set_text(node node, stringnumber text)

Set the text value of a text node. This is only useful for text nodes.

PARAMETERS

node node node to set text for
string text text to setnumber text text to set

gui.set_texture

void gui.set_texture(node node, stringhash texture)

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 for
string texture texture idhash texture 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

gui.set_texture_data

boolean gui.set_texture_data(stringhash texture, number width, number height, stringconstant type, string buffer, boolean flip)

Set the texture buffer data for a dynamically created texture.

PARAMETERS

string texture texture idhash texture texture id
number width texture width
number height texture height
string type texture type
  • "rgb" - RGB
  • "rgba" - RGBA
  • "l" - LUMINANCE
constant type texture type
  • "rgb" - RGB
  • "rgba" - RGBA
  • "l" - LUMINANCE
string buffer texture data
boolean flip flip texture vertically

RETURNS

boolean setting the data was successful

EXAMPLES

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

gui.set_tracking

void gui.set_tracking(node node, number tracking)

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 tracking
number tracking a scaling number for the letter spacing (default=0)

gui.set_visible

void gui.set_visible(node node, boolean visible)

Set if a node should be visible or not. Only visible nodes are rendered.

PARAMETERS

node node node to be visible or not
boolean visible whether the node should be visible or not

gui.set_xanchor

void gui.set_xanchor(node node, constant anchor)

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 for
constant anchor anchor constant
  • gui.ANCHOR_NONE
  • gui.ANCHOR_LEFT
  • gui.ANCHOR_RIGHT

gui.set_yanchor

void gui.set_yanchor(node node, constant anchor)

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 for
constant anchor anchor constant
  • gui.ANCHOR_NONE
  • gui.ANCHOR_TOP
  • gui.ANCHOR_BOTTOM

gui.show_keyboard

void gui.show_keyboard(constant type, boolean autoclose)

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

constant type keyboard type
  • gui.KEYBOARD_TYPE_DEFAULT
  • gui.KEYBOARD_TYPE_EMAIL
  • gui.KEYBOARD_TYPE_NUMBER_PAD
  • gui.KEYBOARD_TYPE_PASSWORD
boolean autoclose if the keyboard should automatically close when clicking outside

gui.stop_particlefx

void gui.stop_particlefx(node node, table [options])

Stops the particle fx for a gui node

PARAMETERS

node node node to stop particle fx for
table [options] options when stopping the particle fx. Supported options:
  • boolean clear: instantly clear spawned particles

init

void init(object self)

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

object self reference to the script state to be used for storing data

EXAMPLES

function init(self)
    -- set up useful data
    self.my_value = 1
end

on_input

nil on_input(object self, hash action_id, table action)

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. The action parameter is a table containing data about the input mapped to the action_id. For mapped actions it specifies the value of the input and if it was just pressed or released. Actions are mapped to input in an input_binding-file. Mouse movement is specifically handled and uses nil as its action_id. The action only contains positional parameters in this case, such as x and y of the pointer. Here is a brief description of the available table fields:

Field Description
value The amount of input given by the user. This is usually 1 for buttons and 0-1 for analogue inputs. This is not present for mouse movement.
pressed If the input was pressed this frame. This is not present for mouse movement.
released If the input was released this frame. This is not present for mouse movement.
repeated If the input was repeated this frame. This is similar to how a key on a keyboard is repeated when you hold it down. This is not present for mouse movement.
x The x value of a pointer device, if present.
y The y value of a pointer device, if present.
screen_x The screen space x value of a pointer device, if present.
screen_y The screen space y value of a pointer device, if present.
dx The change in x value of a pointer device, if present.
dy The change in y value of a pointer device, if present.
screen_dx The change in screen space x value of a pointer device, if present.
screen_dy The change in screen space y value of a pointer device, if present.
gamepad The index of the gamepad device that provided the input.
touch List of touch input, one element per finger, if present. See table below about touch input
Touch input table:
Field Description
id A number identifying the touch input during its duration.
pressed True if the finger was pressed this frame.
released True if the finger was released this frame.
tap_count Number of taps, one for single, two for double-tap, etc
x The x touch location.
y The y touch location.
dx The change in x value.
dy The change in y value.
acc_x Accelerometer x value (if present).
acc_y Accelerometer y value (if present).
acc_z Accelerometer z value (if present).

PARAMETERS

object self reference to the script state to be used for storing data
hash action_id id of the received input action, as mapped in the input_binding-file
table action a table containing the input data, see above for a description

RETURNS

boolean optional boolean to signal if the input should be consumed (not passed on to others) or not, default is false
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

on_message

void on_message(object self, hash message_id, table message)

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

object self reference to the script state to be used for storing data
hash message_id id of the received message
table message a table containing the message data

on_reload

void on_reload(object self)

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

object self reference to the script state to be used for storing data

EXAMPLES

function on_reload(self)
    -- restore some color (or similar)
    gui.set_color(gui.get_node("my_node"), self.my_original_color)
end

update

void update(object self, number dt)

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

object self reference to the script state to be used for storing data
number dt the time-step of the frame update

EXAMPLES

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
        -- increment current score according to the speed
        self.current_score = self.current_score + dt * self.score_update_speed
        -- check if we went past the target score, clamp current score in that case
        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

Constants

gui.ADJUST_FIT

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

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

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.


gui.ANCHOR_BOTTOM

bottom y-anchor


gui.ANCHOR_LEFT

left x-anchor


gui.ANCHOR_NONE

no anchor


gui.ANCHOR_RIGHT

right x-anchor


gui.ANCHOR_TOP

top y-anchor


gui.BLEND_ADD

additive blending


gui.BLEND_ADD_ALPHA

additive alpha blending


gui.BLEND_ALPHA

alpha blending


gui.BLEND_MULT

multiply blending


gui.BLEND_SCREEN

screen blending


gui.CLIPPING_MODE_NONE

clipping mode none


gui.CLIPPING_MODE_STENCIL

clipping mode stencil


gui.EASING_INBACK

in-back


gui.EASING_INBOUNCE

in-bounce


gui.EASING_INCIRC

in-circlic


gui.EASING_INCUBIC

in-cubic


gui.EASING_INELASTIC

in-elastic


gui.EASING_INEXPO

in-exponential


gui.EASING_INOUTBACK

in-out-back


gui.EASING_INOUTBOUNCE

in-out-bounce


gui.EASING_INOUTCIRC

in-out-circlic


gui.EASING_INOUTCUBIC

in-out-cubic


gui.EASING_INOUTELASTIC

in-out-elastic


gui.EASING_INOUTEXPO

in-out-exponential


gui.EASING_INOUTQUAD

in-out-quadratic


gui.EASING_INOUTQUART

in-out-quartic


gui.EASING_INOUTQUINT

in-out-quintic


gui.EASING_INOUTSINE

in-out-sine


gui.EASING_INQUAD

in-quadratic


gui.EASING_INQUART

in-quartic


gui.EASING_INQUINT

in-quintic


gui.EASING_INSINE

in-sine


gui.EASING_LINEAR

linear interpolation


gui.EASING_OUTBACK

out-back


gui.EASING_OUTBOUNCE

out-bounce


gui.EASING_OUTCIRC

out-circlic


gui.EASING_OUTCUBIC

out-cubic


gui.EASING_OUTELASTIC

out-elastic


gui.EASING_OUTEXPO

out-exponential


gui.EASING_OUTINBACK

out-in-back


gui.EASING_OUTINBOUNCE

out-in-bounce


gui.EASING_OUTINCIRC

out-in-circlic


gui.EASING_OUTINCUBIC

out-in-cubic


gui.EASING_OUTINELASTIC

out-in-elastic


gui.EASING_OUTINEXPO

out-in-exponential


gui.EASING_OUTINQUAD

out-in-quadratic


gui.EASING_OUTINQUART

out-in-quartic


gui.EASING_OUTINQUINT

out-in-quintic


gui.EASING_OUTINSINE

out-in-sine


gui.EASING_OUTQUAD

out-quadratic


gui.EASING_OUTQUART

out-quartic


gui.EASING_OUTQUINT

out-quintic


gui.EASING_OUTSINE

out-sine


gui.KEYBOARD_TYPE_DEFAULT

default keyboard


gui.KEYBOARD_TYPE_EMAIL

email keyboard


gui.KEYBOARD_TYPE_NUMBER_PAD

number input keyboard


gui.KEYBOARD_TYPE_PASSWORD

password keyboard


gui.PIEBOUNDS_ELLIPSE

elliptical pie node bounds


gui.PIEBOUNDS_RECTANGLE

rectangular pie node bounds


gui.PIVOT_CENTER

center pivot


gui.PIVOT_E

east pivot


gui.PIVOT_N

north pivot


gui.PIVOT_NE

north-east pivot


gui.PIVOT_NW

north-west pivot


gui.PIVOT_S

south pivot


gui.PIVOT_SE

south-east pivot


gui.PIVOT_SW

south-west pivot


gui.PIVOT_W

west pivot


gui.PLAYBACK_LOOP_BACKWARD

loop backward


gui.PLAYBACK_LOOP_FORWARD

loop forward


gui.PLAYBACK_LOOP_PINGPONG

ping pong loop


gui.PLAYBACK_ONCE_BACKWARD

once backward


gui.PLAYBACK_ONCE_FORWARD

once forward


gui.PLAYBACK_ONCE_PINGPONG

once forward and then backward


gui.PROP_COLOR

color property


gui.PROP_EULER

euler property


gui.PROP_FILL_ANGLE

fill_angle property


gui.PROP_INNER_RADIUS

inner_radius property


gui.PROP_LEADING

leading property


gui.PROP_OUTLINE

outline color property


gui.PROP_POSITION

position property


gui.PROP_ROTATION

rotation property


gui.PROP_SCALE

scale property


gui.PROP_SHADOW

shadow color property


gui.PROP_SIZE

size property


gui.PROP_SLICE9

slice9 property


gui.PROP_TRACKING

tracking property


gui.RESULT_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

The system is out of resources, for instance when trying to create a new texture using gui.new_texture().


gui.RESULT_TEXTURE_ALREADY_EXISTS

The texture id already exists when trying to use gui.new_texture().


gui.SIZE_MODE_AUTO

The size of the node is determined by the currently assigned texture.


gui.SIZE_MODE_MANUAL

The size of the node is determined by the size set in the editor, the constructor or by gui.set_size()


gui.TYPE_BOX

box type


gui.TYPE_CUSTOM

custom type


gui.TYPE_PARTICLEFX

particlefx type


gui.TYPE_PIE

pie type


gui.TYPE_TEXT

text type


Messages

layout_changed

This message is broadcast to every GUI component when a layout change has been initiated on device.

id the id of the layout the engine is changing to
previous_id the id of the layout the engine is changing from

EXAMPLES

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

Properties

fonts

The fonts used in the gui. The type of the property is hash. Key must be specified in options table.

hash gui fonts

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

material

The main material (the default material assigned to a GUI) used when rendering the gui. The type of the property is hash.

hash gui material

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

materials

The materials used when rendering the gui. The type of the property is hash. Key must be specified in options table.

hash gui materials

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

textures

The textures used in the gui. The type of the property is hash. Key must be specified in options table.

hash gui textures

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