mwg API
    Preparing search index...

    Function maskPixels

    • The renderer-free core of ~MASK: base's alpha channel is multiplied by mask's alpha at the given offset (a pixel the mask does not cover keeps zero alpha), base's own colour left untouched. Exported so the masking logic is testable without a canvas.

      Parameters

      • base: Uint8ClampedArray
      • baseWidth: number
      • baseHeight: number
      • mask: Uint8ClampedArray
      • maskWidth: number
      • maskHeight: number
      • offsetX: number
      • offsetY: number

      Returns Uint8ClampedArray

      import { maskPixels } from '@datamoc/mw_games/two-d/render';
      const base = new Uint8ClampedArray([10, 20, 30, 255]); // one opaque pixel
      const mask = new Uint8ClampedArray([0, 0, 0, 128]); // half-alpha mask, same 1x1 size
      const out = maskPixels(base, 1, 1, mask, 1, 1, 0, 0);
      console.log([...out]); // [10, 20, 30, 128]