baochungit/defold-wrap/wrap.gui_object
The base class of a GUI object: a part of a scene with its own hidden root box node, its
own child objects, and the props and settings it is created with. A game subclasses it
with extend, assigns hooks to the subclass, and creates instances with a scene's or
another object's new_object.
- GitHub: baochungit/defold-wrap — pinned to
1.1.0- Pick a release from baochungit/defold-wrap releases and add its Source code (zip) URL (or a packaged
.zipasset, if the library ships one) togame.projectunder[project]dependencies, then Fetch Libraries in the Defold editor. - Run
bunx @defold-typescript/cli resolveto materialize its types. - Import it under a namespace alias of your choice:
import * as gui_object from "wrap.gui_object"
- Pick a release from baochungit/defold-wrap releases and add its Source code (zip) URL (or a packaged
Functions
new(): GuiObject
Returns a new, not yet set up instance of the base class.
Returns
GuiObject
extend<P extends object = {}, S extends object = {}, F extends object = {}>(): GuiObjectClass<P, S, F>
Returns a new subclass: a table indexing the base class, with its own new. Assign
hooks such as init and update to it, and pass it to new_object. P and S type
the props and settings its instances are created with, and F the fields and methods
a game adds to it.
Returns
GuiObjectClass<P, S, F>
Variables
__name: 'GuiObject'
The class name, the value register_modal reads to tell a class from a plain table.
Types
type GuiObjectClass<P extends object = {}, S extends object = {}, F extends object = {}> = GuiObject<P, S> & F & { 'new'(this: void): GuiObject<P, S> & F; }
GuiObject
GuiObject<P extends object = {}, S extends object = {}>
GuiObject.setup(scene: GuiScene, props?: P, settings?: S)
Sets the object up in a scene and runs init. new_object calls it on each new
instance; a game does not.
Parameters
scene:GuiScene— The scene the object belongs to, under whose rootrootis created.props?:P— The object's props. Defaults to{}.settings?:S— The object's settings. Defaults to{}.
GuiObject.is_alive(): boolean | undefined
Returns whether the object is set up and not deleted: nil until setup has run
init, so also during init, then true until delete makes it false.
Returns
boolean | undefined
GuiObject.new_box(position?: Vector3 | Vector4, size?: Vector3): Node
Creates a box node under the object's root, from wrap.node.Node.new_box.
Parameters
position?:Vector3 | Vector4— The node's position.size?:Vector3— The node's size.
Returns
Node
GuiObject.new_text(position?: Vector3 | Vector4, text?: string): Node
Creates a text node under the object's root, from wrap.node.Node.new_text.
Parameters
position?:Vector3 | Vector4— The node's position.text?:string— The node's text.
Returns
Node
GuiObject.new_pie(position?: Vector3 | Vector4, size?: Vector3): Node
Creates a pie node under the object's root, from wrap.node.Node.new_pie.
Parameters
position?:Vector3 | Vector4— The node's position.size?:Vector3— The node's size.
Returns
Node
GuiObject.new_particlefx(position: Vector3 | Vector4 | undefined, particlefx: Hash | string): Node
Creates a particle fx node under the object's root, from wrap.node.Node.new_particlefx.
Parameters
position:Vector3 | Vector4 | undefined— The node's position.particlefx:Hash | string— The particle fx resource name.
Returns
Node
GuiObject.new_object<C extends AnyGuiObjectClass>(object_class: C & Omittable<C['props']> & Omittable<C['settings']>, props?: C['props'], settings?: C['settings']): ReturnType<C['new']>
Creates a child object in the object's scene: calls the class's new, sets the
instance up with setup, which runs its init, and adds it to the objects
bg_update, delete and bg_on_input fan out to.
Parameters
object_class:C & Omittable<C['props']> & Omittable<C['settings']>— A classextendreturns, whose props and settings may both be omitted.props?:C['props']— The child's props. Defaults to{}.settings?:C['settings']— The child's settings. Defaults to{}.
Returns
ReturnType<C['new']>
GuiObject.new_object<C extends AnyGuiObjectClass>(object_class: C & Omittable<C['settings']>, props: C['props'], settings?: C['settings']): ReturnType<C['new']>
Creates a child object whose class needs props, as the first form does.
Parameters
object_class:C & Omittable<C['settings']>— A classextendreturns, whose settings may be omitted.props:C['props']— The child's props.settings?:C['settings']— The child's settings. Defaults to{}.
Returns
ReturnType<C['new']>
GuiObject.new_object<C extends AnyGuiObjectClass>(object_class: C, props: C['props'] | Defaulted<C['props']>, settings: C['settings']): ReturnType<C['new']>
Creates a child object whose class needs settings, as the first form does.
Parameters
object_class:C— A classextendreturns.props:C['props'] | Defaulted<C['props']>— The child's props, orundefinedfor{}when the class allows it.settings:C['settings']— The child's settings.
Returns
ReturnType<C['new']>
GuiObject.init()
Runs once setup has created root, from new_object. A no-op to replace.
GuiObject.update(dt: number)
Runs each frame from bg_update while the object is alive. A no-op to replace.
Parameters
dt:number— The time since the last frame, in seconds.
GuiObject.final()
Runs once from delete, before the child objects and root are deleted. A no-op to
replace.
GuiObject.on_input(action_id: Hash | undefined, action: go.on_input.Action): boolean
Runs from bg_on_input when no child object consumed the input. A no-op to replace.
Parameters
action_id:Hash | undefined— The input action's id, ornilfor mouse movement.action:go.on_input.Action— The input data.
Returns
boolean—trueto consume the input. The no-op returnsfalse.
GuiObject.bg_update(dt: number)
Runs update, then each child object's update, unless the object is not alive.
The scene calls it each frame. At this tag it calls a child's update rather than
its bg_update, so a child's own children are not updated.
Parameters
dt:number— The time since the last frame, in seconds.
GuiObject.delete()
Deletes the object, unless it is not alive: marks it deleted, runs final, deletes
each child object, then deletes root and the nodes under it.
GuiObject.bg_on_input(action_id: Hash | undefined, action: go.on_input.Action): boolean
Offers input to each child object's bg_on_input, the newest first, then to
on_input if none consumed it. Returns false when the object is not alive.
Parameters
action_id:Hash | undefined— The input action's id, ornilfor mouse movement.action:go.on_input.Action— The input data.
Returns
boolean— Whether a child object oron_inputconsumed the input.
GuiObject.scene: GuiScene
The scene the object was created in, set by setup.
GuiObject.root: Node
The object's root, a box node setup creates hidden under its scene's root. Every
node the new_* methods create is its child.
GuiObject.props: P
The props the object was created with, or {} when it was given none.
GuiObject.settings: S
The settings the object was created with, or {} when it was given none.