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

Dragosha/defold-sprite-repeat/sprite_repeat

Sprite texture repeat (tiling) shader helper: reads a sprite'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 sprite_repeat from "sprite_repeat.sprite_repeat"

Functions

create(sprite_url: Url | Hash | string, sprite_id?: Hash | string, self?: { atlas_data?: ReturnType<typeof resource.get_atlas>; tex_info?: ReturnType<typeof resource.get_texture_info>; }): SpriteRepeatAnimation

Reads an atlas animation's frames for a sprite that uses the repeat material, and returns a handle that applies them. Apply the repeat material to the sprite 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

  • sprite_url: Url | Hash | string — The sprite component.
  • sprite_id?: Hash | string — The atlas animation to read. When omitted, the sprite's current animation is used.
  • self?: { atlas_data?: ReturnType<typeof resource.get_atlas>; tex_info?: ReturnType<typeof resource.get_texture_info>; } — The calling script's self. When it already holds atlas_data and tex_info, they are reused instead of read again; otherwise they are read and stored on it, so later calls for sprites sharing the atlas skip the lookup.
    • atlas_data?: ReturnType<typeof resource.get_atlas>
    • tex_info?: ReturnType<typeof resource.get_texture_info>

Returns

  • SpriteRepeatAnimation

Types

SpriteRepeatAnimation

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

Applies the first frame and the repeat factors to the sprite. 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.

SpriteRepeatAnimation.stop()

Cancels the playback timer, if one is running.

SpriteRepeatAnimation.frames: RepeatFrame[]

Every frame of the animation, in playback order.

SpriteRepeatAnimation.width: number

The animation's width, from the atlas.

SpriteRepeatAnimation.height: number

The animation's height, from the atlas.

SpriteRepeatAnimation.fps: number

The animation's playback rate, from the atlas.

SpriteRepeatAnimation.current_frame: number

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

SpriteRepeatAnimation.v: Vector4

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

SpriteRepeatAnimation.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