Class: Spritesheet

PIXI.Spritesheet

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

To access a sprite sheet from your code 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;
  ...
}

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.

new PIXI.Spritesheet (baseTexture, data, resolutionFilename)

Name Type Description
baseTexture PIXI.BaseTexture | PIXI.Texture

Reference to the source BaseTexture object.

data Object

Spritesheet image data.

resolutionFilename string optional

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

Members

PIXI.Spritesheet.BATCH_SIZE number static

The maximum number of Textures to build per process.

Default Value:
  • 1000

animations Object

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

new PIXI.AnimatedSprite(sheet.animations["anim_name"])

baseTexture PIXI.BaseTexture

Reference to ths source texture.

data Object

Reference to the original JSON data.

resolution number

The resolution of the spritesheet.

textures Object

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

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

Methods

destroy (destroyBase)

Destroy Spritesheet and don't use after this.

Name Type Default Description
destroyBase boolean false optional

Whether to destroy the base texture as well

parse (callback)

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

Name Type Description
callback function

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