Class BpxAnimatedSprite

A definition of an animated sprite, which can later be used (indirectly) for drawing by BeetPxDraw.sprite.

It has a form of a collection sprites, originated from the same sprite sheet.

let myAnimation: BpxAnimatedSprite;

$.setOnStarted(() => {
myAnimation = $aspr("spritesheet.png")(8, 8, [
[0,0],
[8,0],
[16,0],
]);
});

$d.setOnDraw(() => {
$d.sprite(myAnimation.current, $v(10));
});

Under the hood this class uses BpxTimer to integrate the animation progression with the game loop.

$aspr

Static factories

Accessors

Methods

Properties

Static factories

  • Parameters

    • imageUrl: string
    • w: number
    • h: number
    • xys: [x: number, y: number][]
    • Optionalopts: {
          frameDuration?: number;
          onGamePause?: "pause" | "ignore";
          paused?: boolean;
      }
      • OptionalframeDuration?: number
      • OptionalonGamePause?: "pause" | "ignore"
      • Optionalpaused?: boolean

    Returns BpxAnimatedSprite

    $aspr

Accessors

Methods

Properties

imageUrl: string
type: "animated" = "animated"

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

const s: BpxSprite | BpxAnimatedSprite = getSprite();
if (s.type === "static") {
// s is BpxSprite here
} else if (s.type === "animated") {
// s is BpxAnimatedSprite here
} else {
$u.assertUnreachable(s);
}