SpriteSheet
Index
Constructors
constructor
Build a new sprite sheet from a list of sprites
Use SpriteSheet.fromImageSource to create a SpriteSheet from an ImageSource organized in a grid
Parameters
options: SpriteSheetOptions
Returns SpriteSheet
Properties
publicreadonlycolumns
publicreadonlyrows
publicreadonlysprites
Methods
publicclone
Returns SpriteSheet
publicgetSprite
Find a sprite by their x/y integer coordinates in the SpriteSheet, for example
getSprite(0, 0)is the Sprite in the top-left andgetSprite(1, 0)is the sprite one to the right.Parameters
x: number
y: number
optionaloptions: GetSpriteOptions
Returns Sprite
publicgetSpriteAsImage
Returns a new image exact size and copy of the original sprite slice.
Useful if you need to apply effects, manipulate, or mutate the image and you don't want to disturb the original sprite sheet.
Parameters
x: number
y: number
Returns Promise<HTMLImageElement>
publicgetSpriteAsStandalone
Returns a sprite that has a new backing image the exact size of the sprite that tha is a copy of the original sprite slice.
Useful if you need to apply effects, manipulate, or mutate the image and you don't want to disturb the original sprite sheet.
Parameters
x: number
y: number
Returns Promise<Sprite>
publicgetTiledSprite
Find a sprite by their x/y integer coordinates in the SpriteSheet and configures tiling to repeat by default, for example
getTiledSprite(0, 0)is the TiledSprite in the top-left andgetTiledSprite(1, 0)is the sprite one to the right.Example:
spriteSheet.getTiledSprite(1, 0, { width: game.screen.width, height: 200, wrapping: { x: ex.ImageWrapping.Repeat, y: ex.ImageWrapping.Clamp } });Parameters
x: number
y: number
optionaloptions: Partial<Omit<TiledSpriteOptions & GraphicOptions, image>>
Returns TiledSprite
publicstaticfromImageSource
Create a SpriteSheet from an ImageSource organized in a grid
Example:
const spriteSheet = SpriteSheet.fromImageSource({ image: imageSource, grid: { rows: 5, columns: 2, spriteWidth: 32, // pixels spriteHeight: 32 // pixels }, // Optionally specify spacing spacing: { // pixels from the top left to start the sprite parsing originOffset: { x: 5, y: 5 }, // pixels between each sprite while parsing margin: { x: 1, y: 1 } } })Parameters
options: SpriteSheetGridOptions
Returns SpriteSheet
publicstaticfromImageSourceWithSourceViews
Create a sprite sheet from a sparse set of SourceView rectangles
Parameters
options: SpriteSheetSparseOptions
Returns SpriteSheet
Represents a collection of sprites from a source image with some organization in a grid