PIXI.Spritesheet

class Spritesheet

Utility class for maintaining reference to a collection of Textures on a single Spritesheet.

To access a sprite sheet from your code you may pass its JSON data file to Pixi's loader:

PIXI.Loader.shared.add("images/spritesheet.json").load(setup);

function setup() {
  let sheet = PIXI.Loader.shared.resources["images/spritesheet.json"].spritesheet;
  ...
}

Alternately, you may circumvent the loader by instantiating the Spritesheet directly:

const sheet = new PIXI.Spritesheet(texture, spritesheetData);
await sheet.parse();
console.log('Spritesheet ready to use!');

With the sheet.textures you can create Sprite objects,sheet.animations can be used to create an AnimatedSprite.

Sprite sheets can be packed using tools like TexturePacker, Shoebox or Spritesheet.js. Default anchor points (see PIXI.Texture#defaultAnchor) and grouping of animation sprites are currently only supported by TexturePacker.

Constructor


new PIXI.Spritesheet(texture: PIXI.BaseTexture | PIXI.Texture, data: object, resolutionFilename: string) → {}
Parameters:
Name Type Default Description
texture PIXI.BaseTexture | PIXI.Texture

Reference to the source BaseTexture object.

data object

Spritesheet image data.

resolutionFilename string undefined

The filename to consider when determining the resolution of the spritesheet. If not provided, the imageUrl will be used on the BaseTexture.

Summary


Properties from Spritesheet

number
static BATCH_SIZE = 1000

The maximum number of Textures to build per process.

Dict<PIXI.Texture[]>
animations
PIXI.BaseTexture
baseTexture

Reference to ths source texture.

object
data
PIXI.Spritesheet[]
linkedSheets

For multi-packed spritesheets, this contains a reference to all the other spritesheets it depends on.

number
resolution

The resolution of the spritesheet.

Dict<PIXI.Texture>
textures

Methods from Spritesheet

Public Properties


BATCH_SIZE Spritesheet.ts:74
static BATCH_SIZE: number = 1000

The maximum number of Textures to build per process.

animations Spritesheet.ts:92
animations: Dict<PIXI.Texture[]>

A map containing the textures for each animation. Can be used to create an AnimatedSprite:

new PIXI.AnimatedSprite(sheet.animations["anim_name"])
baseTexture Spritesheet.ts:80
baseTexture: PIXI.BaseTexture

Reference to ths source texture.

data Spritesheet.ts:101
data: object

Reference to the original JSON data.

linkedSheets Spritesheet.ts:77
linkedSheets: PIXI.Spritesheet[]

For multi-packed spritesheets, this contains a reference to all the other spritesheets it depends on.

resolution Spritesheet.ts:107
resolution: number

The resolution of the spritesheet.

textures Spritesheet.ts:83
textures: Dict<PIXI.Texture>

A map containing all textures of the sprite sheet. Can be used to create a Sprite:

new PIXI.Sprite(sheet.textures["image.png"]);

Public Methods


destroy Spritesheet.ts:358
destroy(destroyBase: boolean) → {void}

Destroy Spritesheet and don't use after this.

Parameters:
Name Type Attributes Default Description
destroyBase boolean

<optional>

false

Whether to destroy the base texture as well

Returns:
Type Description
void
parse Spritesheet.ts:188
parse() → {Promise<PIXI.Texture<Dict>>}

Parser spritesheet from loaded data. This is done asynchronously to prevent creating too many Texture within a single process.

Returns:
Type Description
Promise<PIXI.Texture<Dict>>
parse Spritesheet.ts:195
parse(callback: Function) → {void}
Deprecated: since version 6.5.0

Please use the Promise-based version of this function.

Parameters:
Name Type Attributes Description
callback Function

<optional>

Callback when complete returns a map of the Textures for this spritesheet.

Returns:
Type Description
void

Powered by webdoc!