Builtin types
Every script reaches its own node through the implicit node field, and other nodes through NodeRef fields, Find and Child. Transforms are local to the parent and read and written by value; a 2D method on a 3D node faults. See Nodes, components and references for components and script references.
Example
package demo
import (
"aego/log"
"aego/math"
)
script Door {
@export var OpenAngle float = 90
var frames int
func Ready() {
log.Info("node " + node.Name() + ", 2D: " + string(node.Space() == 0) + ", top level: " + string(node.Parent() == nil))
node.AddTag("Interactable.Door")
log.Info("is interactable: " + string(node.HasTag("Interactable")))
node.SetScale(Vec2{-1, 1})
t := node.Transform2D()
t.Position.X += 2
node.SetTransform2D(t)
log.Info("moved to " + string(node.Position().X) + ", mirrored: " + string(node.Scale().X < 0))
}
func Update(dt float) {
frames++
target := math.Deg2Rad(OpenAngle)
node.SetRotation(math.Min(node.Rotation() + 2 * dt, target))
if frames % 30 == 0 {
log.Info("angle " + string(math.Round(math.Rad2Deg(node.Rotation()))) + " deg")
}
if frames == 100 {
removed := node.RemoveTag("Interactable.Door")
node.SetEnabled(false)
log.Info("tag removed: " + string(removed) + ", enabled: " + string(node.Enabled()))
}
}
}
Functions
| NodeRef.AddTag | (NodeRef) AddTag(tag string) bool | Adds a tag and returns false when it is malformed. |
| NodeRef.Child | (NodeRef) Child(name string) NodeRef | Returns the direct child with this name, or nil. |
| NodeRef.Destroy | (NodeRef) Destroy() | Removes the node and its children at the end of the phase. |
| NodeRef.Enabled | (NodeRef) Enabled() bool | Reports the node's own enabled flag, ignoring its parents. |
| NodeRef.Find | (NodeRef) Find(path string) NodeRef | Resolves a path relative to the node: Weapon/Gun, ../Sibling or /Root/Player. |
| NodeRef.HasTag | (NodeRef) HasTag(tag string) bool | Reports whether the node has the tag or a tag under it: Enemy matches Enemy.Flying. |
| NodeRef.IsAlive | (NodeRef) IsAlive() bool | Reports whether the node exists. It is false right after Destroy. |
| NodeRef.IsPrefabInstance | (NodeRef) IsPrefabInstance() bool | Reports whether the node is a prefab copy or lies inside one. |
| NodeRef.Name | (NodeRef) Name() string | Returns the node name, unique among its siblings. |
| NodeRef.Parent | (NodeRef) Parent() NodeRef | Returns the parent node, or nil for top-level nodes. |
| NodeRef.Position | (NodeRef) Position() Vec2 | Returns the local position relative to the parent. |
| NodeRef.Position3 | (NodeRef) Position3() Vec3 | Returns the local 3D position. |
| NodeRef.PrefabRoot | (NodeRef) PrefabRoot() NodeRef | Returns the root of the nearest prefab copy that holds the node, the node itself for a root, or nil. |
| NodeRef.RemoveTag | (NodeRef) RemoveTag(tag string) bool | Removes a tag and returns whether the node had it. |
| NodeRef.Rotation | (NodeRef) Rotation() float | Returns the local rotation in radians, clockwise. |
| NodeRef.Rotation3 | (NodeRef) Rotation3() Quat | Returns the local 3D rotation. |
| NodeRef.Scale | (NodeRef) Scale() Vec2 | Returns the local scale. |
| NodeRef.SetEnabled | (NodeRef) SetEnabled(enabled bool) | Turns the node on or off. Disabled nodes and their children are not drawn. |
| NodeRef.SetPosition | (NodeRef) SetPosition(p Vec2) | Sets the local position. |
| NodeRef.SetPosition3 | (NodeRef) SetPosition3(p Vec3) | Sets the local 3D position. |
| NodeRef.SetRotation | (NodeRef) SetRotation(radians float) | Sets the local rotation in radians. |
| NodeRef.SetRotation3 | (NodeRef) SetRotation3(q Quat) | Sets the local 3D rotation. |
| NodeRef.SetScale | (NodeRef) SetScale(scale Vec2) | Sets the local scale. A negative X mirrors the node. |
| NodeRef.SetTransform2D | (NodeRef) SetTransform2D(t Transform2D) | Replaces the local 2D transform. |
| NodeRef.SetTransform3D | (NodeRef) SetTransform3D(t Transform3D) | Replaces the local 3D transform. |
| NodeRef.Space | (NodeRef) Space() int | Returns 0 for 2D nodes and 1 for 3D nodes. |
| NodeRef.Transform2D | (NodeRef) Transform2D() Transform2D | Returns a copy of the local 2D transform. Change it and pass it to SetTransform2D. |
| NodeRef.Transform3D | (NodeRef) Transform3D() Transform3D | Returns a copy of the local 3D transform. |
| NodeRef.WorldPosition | (NodeRef) WorldPosition() Vec2 | Returns the position in world space, as of the last transform pass. |
NodeRef.AddTag method
func (NodeRef) AddTag(tag string) bool
Adds a tag and returns false when it is malformed.
Example
node.AddTag("Enemy.Stunned")
NodeRef.Child method
func (NodeRef) Child(name string) NodeRef
Returns the direct child with this name, or nil.
Example
gun := node.Child("Gun")
NodeRef.Destroy method
func (NodeRef) Destroy()
Removes the node and its children at the end of the phase.
Example
node.Destroy()
NodeRef.Enabled method
func (NodeRef) Enabled() bool
Reports the node's own enabled flag, ignoring its parents.
Example
if !Door.Enabled() {
NodeRef.Find method
func (NodeRef) Find(path string) NodeRef
Resolves a path relative to the node: Weapon/Gun, ../Sibling or /Root/Player.
Example
muzzle := node.Find("Weapon/Muzzle")
NodeRef.HasTag method
func (NodeRef) HasTag(tag string) bool
Reports whether the node has the tag or a tag under it: Enemy matches Enemy.Flying.
Example
if other.HasTag("Enemy") {
NodeRef.IsAlive method
func (NodeRef) IsAlive() bool
Reports whether the node exists. It is false right after Destroy.
Example
if Target != nil && Target.IsAlive() {
NodeRef.IsPrefabInstance method
func (NodeRef) IsPrefabInstance() bool
Reports whether the node is a prefab copy or lies inside one.
Example
if node.IsPrefabInstance() {
NodeRef.Name method
func (NodeRef) Name() string
Returns the node name, unique among its siblings.
Example
log.Info(node.Name())
NodeRef.Parent method
func (NodeRef) Parent() NodeRef
Returns the parent node, or nil for top-level nodes.
Example
owner := node.Parent()
NodeRef.Position method
func (NodeRef) Position() Vec2
Returns the local position relative to the parent.
Example
p := node.Position()
NodeRef.Position3 method
func (NodeRef) Position3() Vec3
Returns the local 3D position.
Example
p := node.Position3()
NodeRef.PrefabRoot method
func (NodeRef) PrefabRoot() NodeRef
Returns the root of the nearest prefab copy that holds the node, the node itself for a root, or nil.
Example
owner := node.PrefabRoot()
owner.Destroy()
NodeRef.RemoveTag method
func (NodeRef) RemoveTag(tag string) bool
Removes a tag and returns whether the node had it.
See the module example for this function in use.
NodeRef.Rotation method
func (NodeRef) Rotation() float
Returns the local rotation in radians, clockwise.
Example
a := node.Rotation()
NodeRef.Rotation3 method
func (NodeRef) Rotation3() Quat
Returns the local 3D rotation.
Example
q := node.Rotation3()
NodeRef.Scale method
func (NodeRef) Scale() Vec2
Returns the local scale.
Example
s := node.Scale()
NodeRef.SetEnabled method
func (NodeRef) SetEnabled(enabled bool)
Turns the node on or off. Disabled nodes and their children are not drawn.
Example
Shield.SetEnabled(false)
NodeRef.SetPosition method
func (NodeRef) SetPosition(p Vec2)
Sets the local position.
Example
node.SetPosition(node.Position() + velocity * dt)
NodeRef.SetPosition3 method
func (NodeRef) SetPosition3(p Vec3)
Sets the local 3D position.
Example
node.SetPosition3(node.Position3() + Vec3{0, 0, -Speed * dt})
NodeRef.SetRotation method
func (NodeRef) SetRotation(radians float)
Sets the local rotation in radians.
Example
node.SetRotation(node.Rotation() + Spin * dt)
NodeRef.SetRotation3 method
func (NodeRef) SetRotation3(q Quat)
Sets the local 3D rotation.
Example
node.SetRotation3(math.QuatEuler(0, angle, 0))
NodeRef.SetScale method
func (NodeRef) SetScale(scale Vec2)
Sets the local scale. A negative X mirrors the node.
Example
node.SetScale(Vec2{-1, 1})
NodeRef.SetTransform2D method
func (NodeRef) SetTransform2D(t Transform2D)
Replaces the local 2D transform.
Example
node.SetTransform2D(t)
NodeRef.SetTransform3D method
func (NodeRef) SetTransform3D(t Transform3D)
Replaces the local 3D transform.
Example
node.SetTransform3D(t)
NodeRef.Space method
func (NodeRef) Space() int
Returns 0 for 2D nodes and 1 for 3D nodes.
Example
if node.Space() == 1 {
NodeRef.Transform2D method
func (NodeRef) Transform2D() Transform2D
Returns a copy of the local 2D transform. Change it and pass it to SetTransform2D.
Example
t := node.Transform2D()
t.Position.X += 1
node.SetTransform2D(t)
NodeRef.Transform3D method
func (NodeRef) Transform3D() Transform3D
Returns a copy of the local 3D transform.
Example
t := node.Transform3D()
t.Position.Y += 1
node.SetTransform3D(t)
NodeRef.WorldPosition method
func (NodeRef) WorldPosition() Vec2
Returns the position in world space, as of the last transform pass.
Example
d := math.Dist(node.WorldPosition(), Target.WorldPosition())