|
@@ -1,20 +1,20 @@
|
|
|
-Properties
|
|
|
-==========
|
|
|
+---
|
|
|
+title: Properties in Defold
|
|
|
+brief: This manual explains what types of properties exist in Defold, and how they are used and animated.
|
|
|
+---
|
|
|
|
|
|
-This manual explains what types of properties exist in Defold, and how they are used and animated.
|
|
|
+# Properties
|
|
|
|
|
|
-## Property types
|
|
|
-
|
|
|
-In Defold, there are different sets of properties:
|
|
|
+Defold exposes properties for game objects, components and GUI nodes that can be read, set and animated. The following types of properties exist:
|
|
|
|
|
|
* System defined game object transforms (position, rotation and scale) and component specific properties (for example a sprite's pixel size or a collision object's mass)
|
|
|
-* Script component properties defined in Lua scripts (see [Script properties documentation](/manuals/script-properties) for details)
|
|
|
+* User defined script component properties defined in Lua scripts (see [Script properties documentation](/manuals/script-properties) for details)
|
|
|
* GUI node properties
|
|
|
* Shader constants defined in shaders and material files (see [Material documentation](/manuals/material) for details)
|
|
|
|
|
|
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:
|
|
|
+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:
|
|
|
|
|
|
```lua
|
|
|
-- Set the x positon of "game_object" to 10.
|
|
@@ -38,220 +38,105 @@ local node = gui.get_node("button")
|
|
|
local color = gui.get_color(node)
|
|
|
```
|
|
|
|
|
|
-## System defined game object and component properties
|
|
|
-
|
|
|
-All game objects, and some component types have properties that can be read and manipulated in runtime. Read these values with `[go.get()](/ref/go#go.get)` and write them with `[go.set()](/ref/go#go.set)`. Depending on the property value type, you can animate the values with `[go.animate()](/ref/go#go.animate)`. A small set of the properties are read only.
|
|
|
+## Game object and component properties
|
|
|
|
|
|
-[mark]#get#
|
|
|
-: Can be read with `[go.get()](/ref/go#go.get)`.
|
|
|
+All game objects, and some component types have properties that can be read and manipulated in runtime. Read these values with [`go.get()`](/ref/go#go.get) and write them with [`go.set()`](/ref/go#go.set). Depending on the property value type, you can animate the values with [`go.animate()`](/ref/go#go.animate). A small set of the properties are read only.
|
|
|
|
|
|
+`get`{.mark}
|
|
|
+: Can be read with [`go.get()`](/ref/go#go.get).
|
|
|
|
|
|
-[mark]#get`set#
|
|
|
-: Can be read with `[go.get()](/ref/go#go.get)+ and written with `[go.set()](/ref/go#go.set)`. Numerical values can be animated with `[go.animate()](/ref/go#go.animate)`
|
|
|
-
|
|
|
+`get+set`{.mark}
|
|
|
+: Can be read with [`go.get()`](/ref/go#go.get) and written with [`go.set()`](/ref/go#go.set). Numerical values can be animated with [`go.animate()`](/ref/go#go.animate).
|
|
|
|
|
|
::: sidenote
|
|
|
Legacy functions for reading and writing game object properties also exist. They are `go.get_position()`, `go.set_position()`, `go.get_rotation()`, `go.set_rotation()`, and so forth.
|
|
|
:::
|
|
|
|
|
|
-## GAME OBJECT PROPERTIES
|
|
|
-
|
|
|
-[.table-striped,cols="2,6,2,2"]
|
|
|
-|===
|
|
|
-|*position*
|
|
|
-|The local position of the game object.
|
|
|
-|[type]#vector3#
|
|
|
-|[mark]#get`set#
|
|
|
-
|
|
|
-|*rotation*
|
|
|
-|The local rotation of the game object, expressed as a quaternion.
|
|
|
-|[type]#quaternion#
|
|
|
-|[mark]#get`set#
|
|
|
-
|
|
|
-|*euler*
|
|
|
-|The local rotation of the game object, expressed as Euler angles in degrees.
|
|
|
-|[type]#vector3#
|
|
|
-|[mark]#get`set#
|
|
|
-
|
|
|
-|*scale*
|
|
|
-|The local uniform scale of the game object, expressed as a multiplier. 1 is 100% (original) scale.
|
|
|
-|[type]#number#
|
|
|
-|[mark]#get`set#
|
|
|
-|===
|
|
|
-
|
|
|
-## SPRITE COMPONENT PROPERTIES
|
|
|
-
|
|
|
-[.table-striped,cols="2,6,2,2"]
|
|
|
-|===
|
|
|
-|*size*
|
|
|
-|The non scaled size of the sprite--its size as taken from the source atlas.
|
|
|
-|[type]#vector3#
|
|
|
-|[mark]#get#
|
|
|
-
|
|
|
-|*scale*
|
|
|
-|Non uniform scaling of the sprite, expressed as a vector where each component contains a multiplier along each axis. To double the size in x and y, provide vmath.vector3(2.0, 2.0, 0)
|
|
|
-|[type]#vector3#
|
|
|
-|[mark]#get`set#
|
|
|
-|===
|
|
|
-
|
|
|
-## COLLISION OBJECT COMPONENT PROPERTIES
|
|
|
-
|
|
|
-[.table-striped,cols="2,6,2,2"]
|
|
|
-|===
|
|
|
-|*mass*
|
|
|
-|The mass of the collision object.
|
|
|
-|[type]#number#
|
|
|
-|[mark]#get#
|
|
|
-
|
|
|
-|*linear_velocity*
|
|
|
-|The current linear velocity for the collision object.
|
|
|
-|[type]#vector3#
|
|
|
-|[mark]#get#
|
|
|
-
|
|
|
-|*angular_velocity*
|
|
|
-|The current angular velocity for the collision object.
|
|
|
-|[type]#vector3#
|
|
|
-|[mark]#get#
|
|
|
-
|
|
|
-|*linear_damping*
|
|
|
-|Linear damping for the collision object.
|
|
|
-|[type]#vector3#
|
|
|
-|[mark]#get`set#
|
|
|
-
|
|
|
-|*angular_damping*
|
|
|
-|Angular damping for the collision object.
|
|
|
-|[type]#vector3#
|
|
|
-|[mark]#get`set#
|
|
|
-|===
|
|
|
-
|
|
|
-## SPINE MODEL COMPONENT PROPERTIES
|
|
|
-
|
|
|
-[.table-striped,cols="2,6,2,2"]
|
|
|
-|===
|
|
|
-|*animation*
|
|
|
-|The current animation.
|
|
|
-|[type]#hash#
|
|
|
-|[mark]#get#
|
|
|
-
|
|
|
-|*skin*
|
|
|
-|The currently applied model skin. (cannot be animated!)
|
|
|
-|[type]#hash#
|
|
|
-|[mark]#get`set#
|
|
|
-
|
|
|
-|*cursor*
|
|
|
-|The current position (between 0-1) of the animation playback cursor.
|
|
|
-|[type]#number#
|
|
|
-|[mark]#get`set#
|
|
|
-
|
|
|
-|*playback_rate*
|
|
|
-|The playback rate of the animation. A multiplier to the animation playback rate.
|
|
|
-|[type]#number#
|
|
|
-|[mark]#get`set#
|
|
|
-|===
|
|
|
-
|
|
|
-## MODEL (3D) COMPONENT PROPERTIES
|
|
|
-
|
|
|
-[.table-striped,cols="2,6,2,2"]
|
|
|
-|===
|
|
|
-|*animation*
|
|
|
-|The current animation.
|
|
|
-|[type]#hash#
|
|
|
-|[mark]#get#
|
|
|
-
|
|
|
-|*cursor*
|
|
|
-|The current position (between 0-1) of the animation playback cursor.
|
|
|
-|[type]#number#
|
|
|
-|[mark]#get`set#
|
|
|
-
|
|
|
-|*playback_rate*
|
|
|
-|The playback rate of the animation. A multiplier to the animation playback rate.
|
|
|
-|[type]#number#
|
|
|
-|[mark]#get`set#
|
|
|
-|===
|
|
|
+*GAME OBJECT PROPERTIES*
|
|
|
+
|
|
|
+| property | description | type | |
|
|
|
+| ---------- | -------------------------------------- | --------------- | ---------------- |
|
|
|
+| *position* | The local position of the game object. | `vector3`. | `get+set`{.mark} |
|
|
|
+| *rotation* | Local rotation of game object, expressed as quaternion. | `quaternion` | `get+set`{.mark} |
|
|
|
+| *euler* | Local rotation of game object, Euler angles. | `vector3` | `get+set`{.mark} |
|
|
|
+| *scale* | Local uniform scale of the game object, multiplier. | `number` | `get+set`{.mark} |
|
|
|
+
|
|
|
+*SPRITE COMPONENT PROPERTIES*
|
|
|
+
|
|
|
+| property | description | type | |
|
|
|
+| ---------- | -------------------------------------- | --------------- | ---------------- |
|
|
|
+| *size*. | The non scaled size of the sprite--its size as taken from the source atlas. | `vector3` | `get`{.mark} |
|
|
|
+| *scale* | Non uniform scaling of the sprite, expressed as a vector where each component contains a multiplier along each axis. To double the size in x and y, provide vmath.vector3(2.0, 2.0, 0) | `vector3` | `get+set`{.mark}|
|
|
|
+
|
|
|
+*COLLISION OBJECT COMPONENT PROPERTIES*
|
|
|
+
|
|
|
+| property | description | type | |
|
|
|
+| ---------- | -------------------------------------- | --------------- | ---------------- |
|
|
|
+| *mass* | The mass of the collision object. | `number` | `get`{.mark} |
|
|
|
+| *linear_velocity* | The current linear velocity for the collision object. | `vector3` | `get`{.mark} |
|
|
|
+| *angular_velocity* | The current angular velocity for the collision object. | `vector3` | `get`{.mark} |
|
|
|
+| *linear_damping* | Linear damping for the collision object. | `vector3` | `get+set`{.mark} |
|
|
|
+| *angular_damping* | Angular damping for the collision object. | `vector3` | `get+set`{.mark} |
|
|
|
+
|
|
|
+*SPINE MODEL COMPONENT PROPERTIES*
|
|
|
+
|
|
|
+| property | description | type | |
|
|
|
+| ---------- | -------------------------------------- | --------------- | ---------------- |
|
|
|
+| *animation* | The current animation. | `hash` | `get`{.mark} |
|
|
|
+| *skin*. | The currently applied model skin. (cannot be animated!) | `hash` | `get+set`{.mark} |
|
|
|
+| *cursor* | The current position (between 0-1) of the animation playback cursor. | `number` | get+set`{.mark} |
|
|
|
+| *playback_rate* | The playback rate of the animation. A multiplier to the animation playback rate. | `number` | `get+set`{.mark} |
|
|
|
+
|
|
|
+*MODEL (3D) COMPONENT PROPERTIES*
|
|
|
+
|
|
|
+| property | description | type | |
|
|
|
+| ---------- | -------------------------------------- | --------------- | ---------------- |
|
|
|
+| *animation* | The current animation. | `hash` | `get`{.mark} |
|
|
|
+| *cursor*. | Position (between 0--1) of playback cursor. | `number` | `get+set`{.mark} |
|
|
|
+| *playback_rate* | The playback rate of the animation. A multiplier to the animation playback rate. | `number` | `get+set`{.mark} |
|
|
|
|
|
|
## GUI node properties
|
|
|
|
|
|
GUI nodes also contain properties, but they are read and written through special getter and setter functions. For each property there exist one get- and one set- function. There is also a set of constants defined to use as reference to the properties when animating them. If you need to refer to separate property components you have to use the string name of the property, or a hash of the string name.
|
|
|
|
|
|
-* "position" (or `gui.PROP_POSITION`)
|
|
|
-* "rotation" (or `gui.PROP_ROTATION`)
|
|
|
-* "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`)
|
|
|
-* "slice9" (or `gui.PROP_SLICE9`)
|
|
|
+* `position` (or `gui.PROP_POSITION`)
|
|
|
+* `rotation` (or `gui.PROP_ROTATION`)
|
|
|
+* `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`)
|
|
|
+* `slice9` (or `gui.PROP_SLICE9`)
|
|
|
|
|
|
Note that all color values are encoded in a vector4 where the components correspond to the RGBA values:
|
|
|
|
|
|
-x
|
|
|
+`x`
|
|
|
: The red color component
|
|
|
|
|
|
-y
|
|
|
+`y`
|
|
|
: The green color component
|
|
|
|
|
|
-z
|
|
|
+`z`
|
|
|
: The blue color component
|
|
|
|
|
|
-w
|
|
|
+`w`
|
|
|
: The alpha component
|
|
|
|
|
|
-
|
|
|
## GUI NODE PROPERTIES
|
|
|
|
|
|
-[.table-striped,cols="2,6,2,2"]
|
|
|
-|===
|
|
|
-|*color*
|
|
|
-|The face color of the node.
|
|
|
-|[type]#vector4#
|
|
|
-|gui.get_color() gui.set_color()
|
|
|
-
|
|
|
-|*outline*
|
|
|
-|The outline color of the node.
|
|
|
-|[type]#vector4#
|
|
|
-|gui.get_outline() gui.set_outline()
|
|
|
-
|
|
|
-|*position*
|
|
|
-|The position of the node.
|
|
|
-|[type]#vector3#
|
|
|
-|gui.get_position() gui.set_position()
|
|
|
-
|
|
|
-|*rotation*
|
|
|
-|The rotation of the node expressed as Euler angles--degrees rotated around each axis.
|
|
|
-|[type]#vector3#
|
|
|
-|gui.get_rotation() gui.set_rotation()
|
|
|
-
|
|
|
-|*scale*
|
|
|
-|The scale of the node expressed as a multiplier along each axis.
|
|
|
-|[type]#vector3#
|
|
|
-|gui.get_scale() gui.set_scale()
|
|
|
-
|
|
|
-|*shadow*
|
|
|
-|The shadow color of the node.
|
|
|
-|[type]#vector4#
|
|
|
-|gui.get_shadow() gui.set_shadow()
|
|
|
-
|
|
|
-|*size*
|
|
|
-|The unscaled size of the node.
|
|
|
-|[type]#vector3#
|
|
|
-|gui.get_size() gui.set_size()
|
|
|
-
|
|
|
-|*fill_angle*
|
|
|
-|The fill angle of a pie node expressed as degrees counter-clockwise.
|
|
|
-|[type]#number#
|
|
|
-|gui.get_fill_angle() gui.set_fill_angle()
|
|
|
-
|
|
|
-|*inner_radius*
|
|
|
-|The inner radius of a pie node.
|
|
|
-|[type]#number#
|
|
|
-|gui.get_inner_radius() gui.set_inner_radius()
|
|
|
-
|
|
|
-|*slice9*
|
|
|
-|The edge distances of a slice9 node.
|
|
|
-|[type]#vector4#
|
|
|
-|-
|
|
|
-|===
|
|
|
+| 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 rotation of the node expressed as Euler angles--degrees rotated around each axis. | `vector3` | `gui.get_rotation()` `gui.set_rotation()` |
|
|
|
+| *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()` |
|
|
|
+| *slice9* | The edge distances of a slice9 node. | `vector4` | |
|
|
|
|
|
|
|