Skip to Content
defold-typescript libraries
baochungitdefold-wrap

baochungit/defold-wrap/wrap.go

A chainable wrapper around a game object. new stores a url, and each method calls the go.* function of the same name with that url: setters return the wrapper, so calls chain, and getters return what the engine does.

  • GitHub: baochungit/defold-wrap — pinned to 1.1.0
    1. Pick a release from baochungit/defold-wrap releases and add its Source code (zip) URL (or a packaged .zip asset, if the library ships one) to game.project under [project] dependencies, then Fetch Libraries in the Defold editor.
    2. Run bunx @defold-typescript/cli resolve to materialize its types.
    3. Import it under a namespace alias of your choice:
      import * as go from "wrap.go"

Functions

new(url: SceneGameObjectAddress | Hash | Url): Go

Wraps a game object.

Parameters

  • url: SceneGameObjectAddress | Hash | Url — The game object's url.

Returns

  • Go

Types

type AnimatedValue = number | Vector3 | Vector4 | Quaternion

type PropertyValue = number | boolean | string | Hash | Url | Vector3 | Vector4 | Quaternion | Matrix4 | Vector4[]

Go

Go.get<K extends keyof go.Properties>(property: K, options?: go.GoPropertyOptions): go.Properties[K]

Returns a property of the game object, from go.get.

Parameters

  • property: K — The property.
  • options?: go.GoPropertyOptions — An index, key or keys into the property. Defaults to {}.

Returns

  • go.Properties[K]

Go.get(property: string | Hash, options?: go.GoPropertyOptions): PropertyValue

Returns a property of the game object, from go.get.

Parameters

  • property: string | Hash — The property.
  • options?: go.GoPropertyOptions — An index, key or keys into the property. Defaults to {}.

Returns

  • PropertyValue

Go.set<K extends keyof go.Properties>(property: K, value: go.Properties[K], options?: go.GoPropertyOptions): Go

Sets a property of the game object with go.set.

Parameters

  • property: K — The property.
  • value: go.Properties[K] — The value.
  • options?: go.GoPropertyOptions — An index, key or keys into the property. Defaults to {}.

Returns

  • Go

Go.set(property: string | Hash, value: PropertyValue, options?: go.GoPropertyOptions): Go

Sets a property of the game object with go.set.

Parameters

  • property: string | Hash — The property.
  • value: PropertyValue — The value.
  • options?: go.GoPropertyOptions — An index, key or keys into the property. Defaults to {}.

Returns

  • Go

Go.post<K extends MessageId | Hash | (string & {})>(message_id: K, message?: MessagePayload<K>): Go

Posts a message to the game object with msg.post.

Parameters

  • message_id: K — The message id.
  • message?: MessagePayload<K> — The message payload. Defaults to an empty table.

Returns

  • Go

Go.get_id(): Hash

Returns the game object's id, from go.get_id. go.get_id takes a path string, so call it only on a wrapper built from one.

Returns

  • Hash

Go.delete(recursive?: boolean): Go

Deletes the game object with go.delete. At 1.1.0 the deletion is always recursive: upstream reads recursive or true, so false still deletes the children.

Parameters

  • recursive?: boolean — Whether to delete the children as well.

Returns

  • Go

Go.animate(property: string | Hash, playback: go.Playback, to: AnimatedValue, easing: go.Easing | Vector, duration: number, delay?: number, complete_function?: (self: unknown, url: Url, property: Hash) => void): Go

Animates one property with go.animate.

Parameters

  • property: string | Hash — The property to animate.
  • playback: go.Playback — The playback mode.
  • to: AnimatedValue — The value to animate it to.
  • easing: go.Easing | Vector — An easing constant, or a vector of easing samples.
  • duration: number — The duration in seconds.
  • delay?: number — The delay in seconds before the animation starts. Defaults to 0.
  • complete_function?: (self: unknown, url: Url, property: Hash) => void — Called once the animation completes.

Returns

  • Go

Go.animate(property: readonly (string | Hash)[], playback: go.Playback, to: readonly AnimatedValue[], easing: go.Easing | Vector, duration: number, delay?: number, complete_function?: (self: unknown, url: Url, property: Hash) => void): Go

Animates several properties with go.animate, each to the value at the same index of to, all with the same playback, easing, duration and delay.

Parameters

  • property: readonly (string | Hash)[] — The properties to animate.
  • playback: go.Playback — The playback mode.
  • to: readonly AnimatedValue[] — The value to animate each property to, by index.
  • easing: go.Easing | Vector — An easing constant, or a vector of easing samples.
  • duration: number — The duration in seconds.
  • delay?: number — The delay in seconds before the animations start. Defaults to 0.
  • complete_function?: (self: unknown, url: Url, property: Hash) => void — Called once the first property's animation completes.

Returns

  • Go

Go.cancel_animations(property?: string | Hash | readonly (string | Hash)[]): Go

Cancels the game object's animations with go.cancel_animations.

Parameters

  • property?: string | Hash | readonly (string | Hash)[] — The property, or the properties, whose animations to cancel. When omitted, every animation of the game object is canceled.

Returns

  • Go

Go.set_position(position: Vector3): Go

Sets the game object's position with go.set_position.

Parameters

  • position: Vector3 — The position.

Returns

  • Go

Go.get_position(): Vector3

Returns the game object's position, from go.get_position.

Returns

  • Vector3

Go.add_position(value: Vector3): Go

Meant to add to each component of the position. At 1.1.0 it adds to a copy of the position and leaves the game object unchanged; add_position_x, add_position_y and add_position_z write the result.

Parameters

  • value: Vector3 — The amount to add to each component.

Returns

  • Go

Go.get_position_x(): number

Returns the x component of the game object's position.

Returns

  • number

Go.get_position_y(): number

Returns the y component of the game object's position.

Returns

  • number

Go.get_position_z(): number

Returns the z component of the game object's position.

Returns

  • number

Go.set_position_x(x: number): Go

Sets the x component of the game object's position.

Parameters

  • x: number — The x component.

Returns

  • Go

Go.set_position_y(y: number): Go

Sets the y component of the game object's position.

Parameters

  • y: number — The y component.

Returns

  • Go

Go.set_position_z(z: number): Go

Sets the z component of the game object's position.

Parameters

  • z: number — The z component.

Returns

  • Go

Go.add_position_x(x: number): Go

Adds to the x component of the game object's position.

Parameters

  • x: number — The amount to add.

Returns

  • Go

Go.add_position_y(y: number): Go

Adds to the y component of the game object's position.

Parameters

  • y: number — The amount to add.

Returns

  • Go

Go.add_position_z(z: number): Go

Adds to the z component of the game object's position.

Parameters

  • z: number — The amount to add.

Returns

  • Go

Go.get_rotation(): Quaternion

Returns the game object's rotation, from go.get_rotation.

Returns

  • Quaternion

Go.set_rotation(rotation: Quaternion): Go

Sets the game object's rotation with go.set_rotation.

Parameters

  • rotation: Quaternion — The rotation.

Returns

  • Go

Go.add_rotation(value: Quaternion): Go

Meant to add to the x, y and z components of the rotation quaternion. At 1.1.0 it adds to a copy of the rotation and leaves the game object unchanged.

Parameters

  • value: Quaternion — The amount to add to the x, y and z components.

Returns

  • Go

Go.get_rotation_x(): number

Returns the x component of the rotation quaternion, not an Euler angle.

Returns

  • number

Go.get_rotation_y(): number

Returns the y component of the rotation quaternion, not an Euler angle.

Returns

  • number

Go.get_rotation_z(): number

Returns the z component of the rotation quaternion, not an Euler angle.

Returns

  • number

Go.set_rotation_x(x: number): Go

Sets the x component of the rotation quaternion, not an Euler angle, and leaves the other components as they are.

Parameters

  • x: number — The quaternion's x component.

Returns

  • Go

Go.set_rotation_y(y: number): Go

Sets the y component of the rotation quaternion, not an Euler angle, and leaves the other components as they are.

Parameters

  • y: number — The quaternion's y component.

Returns

  • Go

Go.set_rotation_z(z: number): Go

Sets the z component of the rotation quaternion, not an Euler angle, and leaves the other components as they are.

Parameters

  • z: number — The quaternion's z component.

Returns

  • Go

Go.add_rotation_x(x: number): Go

Adds to the x component of the rotation quaternion, not an Euler angle.

Parameters

  • x: number — The amount to add.

Returns

  • Go

Go.add_rotation_y(y: number): Go

Adds to the y component of the rotation quaternion, not an Euler angle.

Parameters

  • y: number — The amount to add.

Returns

  • Go

Go.add_rotation_z(z: number): Go

Adds to the z component of the rotation quaternion, not an Euler angle.

Parameters

  • z: number — The amount to add.

Returns

  • Go

Go.get_scale(): Vector3

Returns the game object's scale, from go.get_scale.

Returns

  • Vector3

Go.set_scale(scale: number | Vector3): Go

Sets the game object's scale with go.set_scale.

Parameters

  • scale: number | Vector3 — The scale, or one number for all three axes.

Returns

  • Go

Go.add_scale(value: Vector3): Go

Meant to add to each component of the scale. At 1.1.0 it adds to a copy of the scale and leaves the game object unchanged; add_scale_x, add_scale_y and add_scale_z write the result.

Parameters

  • value: Vector3 — The amount to add to each component.

Returns

  • Go

Go.get_scale_x(): number

Returns the x component of the game object's scale.

Returns

  • number

Go.get_scale_y(): number

Returns the y component of the game object's scale.

Returns

  • number

Go.get_scale_z(): number

Returns the z component of the game object's scale.

Returns

  • number

Go.set_scale_x(x: number): Go

Sets the x component of the game object's scale.

Parameters

  • x: number — The x component.

Returns

  • Go

Go.set_scale_y(y: number): Go

Sets the y component of the game object's scale.

Parameters

  • y: number — The y component.

Returns

  • Go

Go.set_scale_z(z: number): Go

Sets the z component of the game object's scale.

Parameters

  • z: number — The z component.

Returns

  • Go

Go.add_scale_x(x: number): Go

Adds to the x component of the game object's scale.

Parameters

  • x: number — The amount to add.

Returns

  • Go

Go.add_scale_y(y: number): Go

Adds to the y component of the game object's scale.

Parameters

  • y: number — The amount to add.

Returns

  • Go

Go.add_scale_z(z: number): Go

Adds to the z component of the game object's scale.

Parameters

  • z: number — The amount to add.

Returns

  • Go

Go.get_parent(): Hash | undefined

Returns the id of the game object's parent, from go.get_parent.

Returns

  • Hash | undefined

Go.set_parent(parent?: SceneGameObjectAddress | Hash | Url, keep_world_transform?: boolean): Go

Sets the game object's parent with go.set_parent.

Parameters

  • parent?: SceneGameObjectAddress | Hash | Url — The parent's url. When omitted, the game object is detached from its parent.
  • keep_world_transform?: boolean — Whether to keep the world transform.

Returns

  • Go

Go.get_scale_uniform(): number

Returns the game object's uniform scale, from go.get_scale_uniform.

Returns

  • number

Go.get_world_position(): Vector3

Returns the game object's world position, from go.get_world_position.

Returns

  • Vector3

Go.get_world_rotation(): Quaternion

Returns the game object's world rotation, from go.get_world_rotation.

Returns

  • Quaternion

Go.get_world_scale(): Vector3

Returns the game object's world scale, from go.get_world_scale.

Returns

  • Vector3

Go.get_world_scale_uniform(): number

Returns the game object's uniform world scale, from go.get_world_scale_uniform.

Returns

  • number

Go.get_world_transform(): Matrix4

Returns the game object's world transform, from go.get_world_transform.

Returns

  • Matrix4

Go.url: SceneGameObjectAddress | Hash | Url

The game object's url, passed to every go.* call.

On this page

Functionsnew(url: SceneGameObjectAddress | Hash | Url): GoTypestype AnimatedValue = number | Vector3 | Vector4 | Quaterniontype PropertyValue = number | boolean | string | Hash | Url | Vector3 | Vector4 | Quaternion | Matrix4 | Vector4[]GoGo.get<K extends keyof go.Properties>(property: K, options?: go.GoPropertyOptions): go.Properties[K]Go.get(property: string | Hash, options?: go.GoPropertyOptions): PropertyValueGo.set<K extends keyof go.Properties>(property: K, value: go.Properties[K], options?: go.GoPropertyOptions): GoGo.set(property: string | Hash, value: PropertyValue, options?: go.GoPropertyOptions): GoGo.post<K extends MessageId | Hash | (string & {})>(message_id: K, message?: MessagePayload<K>): GoGo.get_id(): HashGo.delete(recursive?: boolean): GoGo.animate(property: string | Hash, playback: go.Playback, to: AnimatedValue, easing: go.Easing | Vector, duration: number, delay?: number, complete_function?: (self: unknown, url: Url, property: Hash) => void): GoGo.animate(property: readonly (string | Hash)[], playback: go.Playback, to: readonly AnimatedValue[], easing: go.Easing | Vector, duration: number, delay?: number, complete_function?: (self: unknown, url: Url, property: Hash) => void): GoGo.cancel_animations(property?: string | Hash | readonly (string | Hash)[]): GoGo.set_position(position: Vector3): GoGo.get_position(): Vector3Go.add_position(value: Vector3): GoGo.get_position_x(): numberGo.get_position_y(): numberGo.get_position_z(): numberGo.set_position_x(x: number): GoGo.set_position_y(y: number): GoGo.set_position_z(z: number): GoGo.add_position_x(x: number): GoGo.add_position_y(y: number): GoGo.add_position_z(z: number): GoGo.get_rotation(): QuaternionGo.set_rotation(rotation: Quaternion): GoGo.add_rotation(value: Quaternion): GoGo.get_rotation_x(): numberGo.get_rotation_y(): numberGo.get_rotation_z(): numberGo.set_rotation_x(x: number): GoGo.set_rotation_y(y: number): GoGo.set_rotation_z(z: number): GoGo.add_rotation_x(x: number): GoGo.add_rotation_y(y: number): GoGo.add_rotation_z(z: number): GoGo.get_scale(): Vector3Go.set_scale(scale: number | Vector3): GoGo.add_scale(value: Vector3): GoGo.get_scale_x(): numberGo.get_scale_y(): numberGo.get_scale_z(): numberGo.set_scale_x(x: number): GoGo.set_scale_y(y: number): GoGo.set_scale_z(z: number): GoGo.add_scale_x(x: number): GoGo.add_scale_y(y: number): GoGo.add_scale_z(z: number): GoGo.get_parent(): Hash | undefinedGo.set_parent(parent?: SceneGameObjectAddress | Hash | Url, keep_world_transform?: boolean): GoGo.get_scale_uniform(): numberGo.get_world_position(): Vector3Go.get_world_rotation(): QuaternionGo.get_world_scale(): Vector3Go.get_world_scale_uniform(): numberGo.get_world_transform(): Matrix4Go.url: SceneGameObjectAddress | Hash | Url