Skip to Content
defold-typescript libraries
indiesoftby

indiesoftby/defold-dissolve-fx/dissolve_fx

A dissolve effect for sprites. Add a noise and a ramp image to the sprite's atlas and set dissolve_fx/materials/sprite.material as the sprite's material, then call init from the script's init. The noise drives the dissolve and the ramp colors its burning edge.

  • GitHub: indiesoftby/defold-dissolve-fx — pinned to 1.2.0
    1. Pick a release from indiesoftby/defold-dissolve-fx 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 dissolve_fx from "dissolve_fx.dissolve_fx"

Functions

find_uvrect(sprite_url: string | Hash | Url, image_id: string, scale_mode?: ScaleMode): LuaMultiReturn<[ number, number, number, number ]>

Finds an image in the sprite's atlas and returns its uv rect in texture space as four values: center x, center y, width and height: const [x, y, w, h] = dissolve_fx.find_uvrect("#sprite", "noise"). Upstream asserts that image_id is a string, that the atlas holds the image, and that the image is not trimmed (trim mode off, 8 uvs). With scale_mode, the width and height are also divided by the size of the sprite's current animation, so the vertex shader can map the noise from local positions.

Parameters

  • sprite_url: string | Hash | Url — The sprite component.
  • image_id: string — The image's id in the sprite's atlas.
  • scale_mode?: ScaleMode — How the width and height are scaled to the sprite. Upstream asserts stretch or cover. When omitted, they are left in texture space.

Returns

  • LuaMultiReturn<[ number, number, number, number ]>

init(sprite_url: string | Hash | Url, noise_image: string, ramp_image: string, noise_scale_mode?: ScaleMode)

Sets the sprite's noise_uvrect and ramp_uvrect from the two images in its atlas. The sprite must use the dissolve_fx/materials/sprite.material material. The effect is then driven by the sprite's dissolve.z property, the size of the burning edge, and dissolve.w, from 0 to 1, through go.set and go.animate: go.animate("#sprite", "dissolve.w", go.PLAYBACK_LOOP_PINGPONG, 1, go.EASING_LINEAR, 3).

Parameters

  • sprite_url: string | Hash | Url — The sprite component with the dissolve material.
  • noise_image: string — The noise image's id in the sprite's atlas.
  • ramp_image: string — The ramp image's id in the sprite's atlas.
  • noise_scale_mode?: ScaleMode — How the noise is scaled to the sprite. Defaults to stretch.

Types

type ScaleMode = "stretch" | "cover"

On this page