Skip to Content
defold-typescript libraries
Dragoshadefold-sprite-repeat

Dragosha/defold-sprite-repeat/node_repeat

GUI box node texture repeat (tiling) shader helper: reads a box node's atlas animation and drives the repeat material's constants.

  • GitHub: Dragosha/defold-sprite-repeat — pinned to v0.3
    1. Pick a release from Dragosha/defold-sprite-repeat 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 node_repeat from "node_repeat.node_repeat"

Functions

create(node_or_string: Opaque<"node"> | string, animation_id: Hash | string | undefined, atlas_path: Hash | string): NodeRepeatAnimation

Reads an atlas animation's frames for a GUI box node that uses the repeat material, and returns a handle that applies them. Call it from a GUI script. Apply the repeat material to the node first, and disable sprite trim mode for the atlas images: every frame must have exactly 8 UV values, or this asserts. Walks the atlas animation's frame list, so it needs Defold 1.12.3 or later.

Parameters

  • node_or_string: Opaque<"node"> | string — The box node, or its id.
  • animation_id: Hash | string | undefined — The atlas animation to read. Pass undefined to use the node's current flipbook.
  • atlas_path: Hash | string — The atlas resource path, passed to resource.get_atlas. Asserted present.

Returns

  • NodeRepeatAnimation

get_screen_aspect_ratio(): LuaMultiReturn<[ number, number ]>

Measures how the window is stretched relative to the GUI's design size, stores the result in x_ratio and y_ratio, and returns it. The smaller ratio is always 1. Call it from a GUI script.

Returns

  • LuaMultiReturn<[ number, number ]> — The horizontal and vertical ratios.

Variables

x_ratio: number

The horizontal stretch of the window relative to the GUI's design size, divided by the smaller of the two stretches. Starts at 1; get_screen_aspect_ratio updates it.

y_ratio: number

The vertical stretch of the window relative to the GUI's design size, divided by the smaller of the two stretches. Starts at 1; get_screen_aspect_ratio updates it.

Types

NodeRepeatAnimation

NodeRepeatAnimation.animate(repeat_x: number, repeat_y: number)

Applies the first frame and the repeat factors to the node. When the animation has more than one frame and a non-zero fps, starts a repeating timer that steps through the frames.

Parameters

  • repeat_x: number — How many times the image repeats horizontally.
  • repeat_y: number — How many times the image repeats vertically.

NodeRepeatAnimation.stop()

Cancels the playback timer, if one is running.

NodeRepeatAnimation.update(repeat_x?: number, repeat_y?: number)

Changes the repeat factors and applies them to the node. A factor left out keeps its current value.

Parameters

  • repeat_x?: number — How many times the image repeats horizontally.
  • repeat_y?: number — How many times the image repeats vertically.

NodeRepeatAnimation.frames: RepeatFrame[]

Every frame of the animation, in playback order.

NodeRepeatAnimation.width: number

The animation's width, from the atlas.

NodeRepeatAnimation.height: number

The animation's height, from the atlas.

NodeRepeatAnimation.fps: number

The animation's playback rate, from the atlas.

NodeRepeatAnimation.current_frame: number

The 1-based index of the frame shown next. ⚠️ 1-based; passed to node_repeat unchanged.

NodeRepeatAnimation.v: Vector4

The uv_repeat value: x/y the repeat factors, z/w the current frame's size.

NodeRepeatAnimation.node: Opaque<"node">

The box node the animation drives.

NodeRepeatAnimation.handle?: number

The timer.delay handle driving playback. Present only while a multi-frame animation plays.

RepeatFrame

RepeatFrame.uv_coord: Vector4

The frame's UV rectangle in the texture: x/y one corner, z/w the other.

RepeatFrame.w: number

The frame's width in texture pixels.

RepeatFrame.h: number

The frame's height in texture pixels.

RepeatFrame.uv_rotated: Vector4

(0, 1, 0, 0) when the atlas stores the frame rotated clockwise, else (1, 0, 0, 0).

On this page