Class BpxSpriteColorMapping

Static values

Static factories

Methods

Properties

Static values

noMapping: BpxSpriteColorMapping = ...

A mapping used by default, which takes sprite colors as they are, without any changes. An equivalent of BpxSpriteColorMapping.of((c, _x, _y) => c).

Static factories

  • Creates a simplified color mapping, based on a map of sprite colors to the new ones.

    null can be used to map a given sprite color into a transparency. It is useful e.g. when we have a sprite with a black used as a background, so we can treat all black pixels as transparent when drawing.

    Parameters

    Returns BpxSpriteColorMapping

    BpxSpriteColorMapping.from([
    [$rgb_red, $rgb_green],
    [$rgb_blue, $rgb_green],
    [$rgb_yellow, null],
    ]);

Methods

Properties

type: "sprite_mapping" = "sprite_mapping"

A property helpful for TypeScript type inference, when distinguishing from other types of colors.

const c:
| null
| BpxRgbColor
| BpxPatternColors
| BpxSpriteColorMapping
| BpxCanvasSnapshotColorMapping
= getColor();
if (c == null) {
// c is transparent here
} else if (c.type === "rgb") {
// c is BpxRgbColor here
} else if (c.type === "pattern") {
// c is BpxPatternColors here
} else if (c.type === "sprite_mapping") {
// c is BpxSpriteColorMapping here
} else if (c.type === "canvas_snapshot_mapping") {
// c is BpxCanvasSnapshotColorMapping here
} else {
$u.assertUnreachable(c);
}