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) → {}
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 |
The maximum number of Textures to build per process. |
Dict<PIXI.Texture[]> |
|
PIXI.BaseTexture |
Reference to ths source texture. |
object |
|
PIXI.Spritesheet[] |
For multi-packed spritesheets, this contains a reference to all the other spritesheets it depends on. |
number |
The resolution of the spritesheet. |
Dict<PIXI.Texture> |
|
Methods from Spritesheet
void |
|
Promise<PIXI.Texture<Dict>> |
|
void |
|
Public Properties
static BATCH_SIZE: number = 1000
The maximum number of Textures to build per process.
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"])
linkedSheets: PIXI.Spritesheet[]
For multi-packed spritesheets, this contains a reference to all the other spritesheets it depends on.
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(destroyBase: boolean) → {void}
Destroy Spritesheet and don't use after this.
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
destroyBase | boolean |
<optional> |
false |
Whether to destroy the base texture as well |
Type | Description |
---|---|
void |
parse() → {Promise<PIXI.Texture<Dict>>}
Parser spritesheet from loaded data. This is done asynchronously to prevent creating too many Texture within a single process.
Type | Description |
---|---|
Promise<PIXI.Texture<Dict>> |
parse(callback: Function) → {void}
Please use the Promise-based version of this function.
Name | Type | Attributes | Description |
---|---|---|---|
callback | Function |
<optional> |
Callback when complete returns a map of the Textures for this spritesheet. |
Type | Description |
---|---|
void |