Defold exposes properties for game objects, components and GUI nodes that can be read, set and animated. The following types of properties exist:
Numeric properties display a drag handle when you hover over their input field. You can increase/decrease their value, by dragging the handle right/left or up/down respectively.
Depending on where a property is found, you access it via a generic function, or a property-specific function. Many of the properties can be automatically animated. Animating properties through the built-in system is highly recommended over manipulating the properties yourself (inside an update() function), both for performance reasons as well as convenience.
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 example, to set the x-component of a game object’s position:
-- Set the x position of "game_object" to 10.
go.set("game_object", "position.x", 10)
The functions go.get(), go.set() and go.animate() take a reference as their first parameter and a property identifier as their second. The reference identifies the game object or component and can be a string, a hash or a URL. URLs are explained in detail in the addressing manual. The property identifier is a string or hash that names the property:
-- Set the x-scale of the sprite component
local url = msg.url("#sprite")
local prop = hash("scale.x")
go.set(url, prop, 2.0)
For GUI nodes, the node is provided as the first parameter to either a property-specific function or the generic gui.get() and gui.set() functions:
-- Get the color of the button
local node = gui.get_node("button")
local color = gui.get_color(node)
local same_color = gui.get(node, "color")
gui.set(node, "color.x", 1)
All game objects, and some component types have properties that can be read and manipulated in runtime. Read these values with go.get() and write them with go.set(). Depending on the property value type, you can animate the values with go.animate(). A small set of the properties are read only.
getgo.get().get+setgo.get() and written with go.set(). Numerical values can be animated with go.animate().GAME OBJECT PROPERTIES
| property | description | type | |
|---|---|---|---|
| position | The local position of the game object. | vector3 |
get+set |
| rotation | Local rotation of game object, expressed as a quaternion. |
quaternion |
get+set |
| euler | Local rotation of game object, Euler angles. | vector3 |
get+set |
| scale | Local non uniform scale of the game object, expressed as a vector where each component contains a multiplier along each axis. To double the size in X and Y without changing Z, use vmath.vector3(2.0, 2.0, 1.0). |
vector3 |
get+set |
| scale.xy | Local non uniform scale of the game object along the X and Y axes. Use this property or go.set_scale_xy() when Z scaling is not intended. |
vector3 |
get+set |
Specific functions for working with the game object transform also exist; they are go.get_position(), go.set_position(), go.get_rotation(), go.set_rotation(), go.get_scale(), go.set_scale() and go.set_scale_xy().
SPRITE COMPONENT PROPERTIES
| property | description | type | |
|---|---|---|---|
| size | The non scaled size of the sprite—its size as taken from the source atlas. | vector3 |
get |
| image | The texture path hash of the sprite. | hash |
get |
| scale | Non uniform scale of the sprite . | vector3 |
get+set |
| scale.xy | Non uniform scale of the sprite along X and Y axis. | vector3 |
get+set |
| material | The material used by the sprite. | hash |
get+set |
| cursor | Position (between 0–1) of playback cursor. | number |
get+set |
| playback_rate | The framerate of the flipbook animation. | number |
get+set |
COLLISION OBJECT COMPONENT PROPERTIES
| property | description | type | |
|---|---|---|---|
| mass | The mass of the collision object. | number |
get |
| linear_velocity | The current linear velocity of the collision object. | vector3 |
get |
| angular_velocity | The current angular velocity of the collision object. | vector3 |
get |
| linear_damping | Linear damping of the collision object. | vector3 |
get+set |
| angular_damping | Angular damping of the collision object. | vector3 |
get+set |
MODEL (3D) COMPONENT PROPERTIES
| property | description | type | |
|---|---|---|---|
| animation | The current animation. | hash |
get |
| texture0–texture15 | The texture path hashes of the model. | hash |
get+set |
| cursor | Position (between 0–1) of playback cursor. | number |
get+set |
| playback_rate | The playback rate of the animation. A multiplier to the animation playback rate. | number |
get+set |
| material | The material used by the model. | hash |
get+set |
LABEL COMPONENT PROPERTIES
| property | description | type | |
|---|---|---|---|
| scale | The scale of the label. | vector3 |
get+set |
| scale.xy | The scale of the label along X and Y axis. | vector3 |
get+set |
| color | The color of the label. | vector4 |
get+set |
| outline | The outline color of the label. | vector4 |
get+set |
| shadow | The shadow color of the label. | vector4 |
get+set |
| size | The size of the label. The size will constrain the text if line break is enabled. | vector3 |
get+set |
| material | The material used by the label. | hash |
get+set |
| font | The font used by the label. | hash |
get+set |
GUI nodes have property-specific getter and setter functions, such as gui.get_position() and gui.set_position(). The built-in properties listed below can alternatively be read and written with gui.get(node, property) and gui.set(node, property, value). Other node values may still require their dedicated functions. Material constants on GUI nodes also use the generic functions. To address one component of a vector property, append its name, for example gui.set(node, "color.x", 1).
The generic and property-specific functions do not always use identical value types. gui.get() returns a vector4 for the complete position, scale, size, and euler properties, while the corresponding property-specific functions return a vector3. gui.set() accepts either a vector3 or vector4 for those properties. The generic rotation property uses a quaternion; use euler when setting rotation in degrees.
position (or gui.PROP_POSITION)rotation (or gui.PROP_ROTATION)euler (or gui.PROP_EULER)scale (or gui.PROP_SCALE)color (or gui.PROP_COLOR)outline (or gui.PROP_OUTLINE)shadow (or gui.PROP_SHADOW)size (or gui.PROP_SIZE)fill_angle (or gui.PROP_FILL_ANGLE)inner_radius (or gui.PROP_INNER_RADIUS)leading (or gui.PROP_LEADING)tracking (or gui.PROP_TRACKING)slice9 (or gui.PROP_SLICE9)Note that all color values are encoded in a vector4 where the components correspond to the RGBA values:
xyzwGUI NODE PROPERTIES
| property | description | type | |
|---|---|---|---|
| color | The face color of the node. | vector4 |
gui.get_color() gui.set_color() |
| outline | The outline color of the node. | vector4 |
gui.get_outline() gui.set_outline() |
| position | The position of the node. | vector3 |
gui.get_position() gui.set_position() |
| rotation | The node rotation. The getter returns a quaternion; the setter accepts a quaternion or Euler angles as a vector. | quaternion, vector3, or vector4 |
gui.get_rotation() gui.set_rotation() |
| euler | The rotation of the node expressed as Euler angles in degrees. | vector3 |
gui.get_euler() gui.set_euler() |
| scale | The scale of the node expressed as a multiplier along each axis. | vector3 |
gui.get_scale() gui.set_scale() |
| shadow | The shadow color of the node. | vector4 |
gui.get_shadow() gui.set_shadow() |
| size | The unscaled size of the node. | vector3 |
gui.get_size() gui.set_size() |
| fill_angle | The fill angle of a pie node expressed as degrees counter-clockwise. | number |
gui.get_fill_angle() gui.set_fill_angle() |
| inner_radius | The inner radius of a pie node. | number |
gui.get_inner_radius() gui.set_inner_radius() |
| leading | The line-spacing scale of a text node. | number |
gui.get_leading() gui.set_leading() |
| tracking | The letter-spacing scale of a text node. | number |
gui.get_tracking() gui.set_tracking() |
| slice9 | The edge distances of a slice9 node. | vector4 |
gui.get_slice9() gui.set_slice9() |