Skip to Content
defold-typescript libraries
baochungitdefold-wrap

baochungit/defold-wrap/wrap.gui_applet

A GUI applet: a node that shows one scene at a time, playing the old scene's transition out while the new one transitions in. A GUI script creates it with new, and calls its update, final, on_message and on_input from its own, which drive the scenes.

  • 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 gui_applet from "wrap.gui_applet"

Functions

new(2 overloads): GuiApplet

  1. (root: string | Opaque<'node'>, scene?: GuiSceneClass<object>)

    Creates an applet on a node and, when given a scene class, shows a new scene of it.

    Parameters

    • root: string | Opaque<'node'> — The node, or the id gui.get_node looks it up by.
    • scene?: GuiSceneClass<object> — A class wrap.gui_scene.extend returns.
  2. <F extends object = {}>(root: string | Opaque<'node'>, scene: GuiSceneHooks<F>)

    Creates an applet on a node and shows a scene built from a plain table of hooks and fields, copied onto a fresh wrap.gui_scene.extend().

    Parameters

    • root: string | Opaque<'node'> — The node, or the id gui.get_node looks it up by.
    • scene: GuiSceneHooks<F> — The hooks and fields, each hook seeing the scene as this.

Returns

  • GuiApplet

Variables

__name: 'GuiApplet'

The class name.

Types

GuiApplet

GuiApplet.register_scene(name: string, scene: GuiSceneClass<object>)

Registers a scene class under a name, for show_scene to show.

Parameters

  • name: string — The name show_scene takes.
  • scene: GuiSceneClass<object> — A class wrap.gui_scene.extend returns.

GuiApplet.register_scene<F extends object = {}>(name: string, scene: GuiSceneHooks<F>)

Registers a scene built from a plain table of hooks and fields, whose keys are copied onto a fresh wrap.gui_scene.extend() once, at registration.

Parameters

  • name: string — The name show_scene takes.
  • scene: GuiSceneHooks<F> — The hooks and fields, each hook seeing the scene as this.

GuiApplet.unregister_scene(name: string)

Removes the scene registered under a name.

Parameters

  • name: string — The name it was registered under.

GuiApplet.show_scene(name_or_scene: string | GuiSceneClass<object>)

Shows a new scene of a class, or of the class registered under a name: sets it up with setup, which runs its init, starts its transition in, and starts the transition out of the scene it replaces. Does nothing when no scene is registered under the name.

Parameters

  • name_or_scene: string | GuiSceneClass<object> — The name the scene was registered under, or a class wrap.gui_scene.extend returns.

GuiApplet.show_scene<F extends object = {}>(name_or_scene: GuiSceneHooks<F>)

Shows a scene built from a plain table of hooks and fields, as the first form does. The keys are copied onto a fresh wrap.gui_scene.extend(), which is the scene shown.

Parameters

  • name_or_scene: GuiSceneHooks<F> — The hooks and fields, each hook seeing the scene as this.

GuiApplet.get_size(): Vector3

Returns the size of the applet's root node, from wrap.node.Node.get_size.

Returns

  • Vector3

GuiApplet.update(dt: number)

Runs bg_update on the scene transitioning out, if any, then on the current scene. Call it from the GUI script's update.

Parameters

  • dt: number — The time since the last frame, in seconds.

GuiApplet.final()

Finalizes the current scene with bg_final. Call it from the GUI script's final.

GuiApplet.on_message(message_id: Hash, message: Record<string | number, unknown>, sender: Url)

Passes a message to the current scene's bg_on_message. Call it from the GUI script's on_message.

Parameters

  • message_id: Hash — The message's id.
  • message: Record<string | number, unknown> — The message's data.
  • sender: Url — The url of the message's sender.

GuiApplet.on_input(action_id: Hash | undefined, action: go.on_input.Action): boolean

Passes input to the current scene's bg_on_input. Call it from the GUI script's on_input, and return what it returns.

Parameters

  • action_id: Hash | undefined — The input action's id, or nil for mouse movement.
  • action: go.on_input.Action — The input data.

Returns

  • boolean — Whether the scene consumed the input; false when no scene is shown.

GuiApplet.root: Node

The wrapped node the applet was created on. Each scene's root is created under it.

On this page