mwg API
    Preparing search index...

    Class TintedSprite

    A sprite that can be pulled towards a colour, not just darkened.

    tint multiplies, as it does on any Pixi sprite. colorAdd is added on top, which is what makes effects like these possible.

    import { TintedSprite } from '@datamoc/mw_games/two-d/render';
    import type { Texture2D } from '@datamoc/mw_games/two-d/render';

    declare const texture: Texture2D;

    const rat = new TintedSprite({ texture });
    rat.lerpTint(0x00ff00, 0.5); // half-way to green: poisoned
    rat.lerpTint(0xffffff, 0.8); // nearly white: just took a hit
    rat.tint = 0x404060; // plain multiply: standing in the dark
    rat.silhouette(0x000000); // a solid black shape, keeping only the sprite's outline

    const ghost = new TintedSprite({ texture });
    ghost.alpha = 0.5; // translucent: a spectral/ghost-type enemy
    ghost.lerpTint(0x8080ff, 0.3); // both compose freely: a pale, faintly-blue-tinted ghost

    Both terms ride in the same batch, so a screen full of tinted sprites is still one draw call. See ColorTransformBatcher for how, and for the caveat about Pixi internals.

    alpha (inherited from Pixi's own Sprite) composes with both terms for free: this class only adds one vertex attribute (colorAdd) onto Pixi's own colour+alpha packing (groupColorAlpha), it never replaces or shadows it, so ordinary translucency - a see-through ghost, a fade-in/out, a cloaking preview - needs no extra API here. Verified live, not just by reading the packing code: a TintedSprite with alpha = 0.35 renders genuinely see-through (the texture behind it shows through), the same as any plain Pixi Sprite.

    Hierarchy (View Summary)

    Index
    • Moves the sprite strength of the way towards color, leaving its shading intact.

      This sets both halves of the transform: the tint carries 1 - strength and the additive term carries color × strength.

      Parameters

      • color: number
      • strength: number

      Returns void

    • Parameters

      • r: number
      • g: number
      • b: number

        each 0 to 1

      • a: number = 0

        extra alpha to add, usually 0

      Returns void

    • a solid silhouette in color, keeping only the sprite's shape

      Parameters

      • color: number

      Returns void