Skip to content

Costume

An image a sprite (or the stage) can wear. Each sprite owns a list of costumes and shows one at a time; switching costumes is how a sprite changes its appearance or animates.

The Costume engine class. Most members are available as free functions; this page documents the underlying API for advanced use.

Costume.center: { x: number; y: number }

The point inside the costume that lines up with the sprite’s position.

Since 1.0.0

Costume.height: number

The costume’s drawn height in pixels, after scaling is applied.

Since 1.0.0

Costume.img: HTMLImageElement

The loaded image element that holds this costume’s picture.

Since 1.0.0

Costume.isBitmap: boolean

Whether this costume is a bitmap image (true) rather than an SVG (false).

Since 1.0.0

Costume.name: string

The name used to identify and switch to this costume.

Since 1.0.0

Costume.resolution: 2 | 1

How many image pixels map to each costume pixel (2 for most bitmaps, 1 for SVGs).

Since 1.0.0

Costume.scale: number

How much the costume’s image is scaled when drawn.

Since 1.0.0

Costume.url: string

The source URL where this costume’s image is loaded from.

Since 1.0.0

Costume.width: number

The costume’s drawn width in pixels, after scaling is applied.

Since 1.0.0