class SpriteAtlas: Object

A simple sprite atlas. Used by spectrum.Display to render cells and actors.

image: any

The texture atlas love image

quadsByName: table<string, love.graphics.Quad>

A table of quads indexed by sprite names

quadsByIndex: table<number, love.graphics.Quad>

A table of quads indexed by sprite indices

__new(
    self: SpriteAtlas,
    imagePath: string,
    spriteData: table,
    names?: string[]
)

The constructor for the SpriteAtlas class.

Parameters:
  • imagePath (string) – The path to the texture atlas image.

  • spriteData (table) – A table containing sprite names and their respective quads.

getQuadByName(self: SpriteAtlas, name: string): (quad?: love.graphics.Quad)

Gets a quad by name.

Parameters:

name (string) – The name of the sprite.

Returns:

quad? (love.graphics.Quad) – The love quad associated with the sprite name.

getQuadByIndex(self: SpriteAtlas, index: number): (quad?: love.graphics.Quad)

Gets a quad by index.

Parameters:

index (number) – The index of the sprite.

Returns:

quad? (love.graphics.Quad) – The love quad associated with the sprite index.

drawByName(self: SpriteAtlas, name: string, x: number, y: number)

Draws a sprite by name at the given position.

Parameters:
  • name (string) – The name of the sprite.

  • x (number) – The x coordinate to draw the sprite.

  • y (number) – The y coordinate to draw the sprite.

drawByIndex(self: SpriteAtlas, index: number, x: number, y: number)

Draws a sprite by index at the given position.

Parameters:
  • index (number) – The index of the sprite.

  • x (number) – The x coordinate to draw the sprite.

  • y (number) – The y coordinate to draw the sprite.

staticmethod fromAtlased(imagePath: string, jsonPath: string): SpriteAtlas

Creates a SpriteAtlas from an Atlased JSON and PNG file.

Parameters:
  • imagePath (string) – The path to the texture atlas image.

  • jsonPath (string) – The path to the Atlased JSON file.

Returns:

_1 (SpriteAtlas) – The created SpriteAtlas instance.

staticmethod fromGrid(
    imagePath: string,
    cellWidth: number,
    cellHeight: number,
    names?: string[]
): SpriteAtlas

Creates a SpriteAtlas from a grid of cells.

Parameters:
  • imagePath (string) – The path to the texture atlas image.

  • cellWidth (number) – The width of each cell in the grid.

  • cellHeight (number) – The height of each cell in the grid.

  • names? (string[]) – The names of the sprites, mapping left to right, top to bottom. If not supplied the quads will be sorted by index not name.

Returns:

_1 (SpriteAtlas) – The created SpriteAtlas instance.

staticmethod fromASCIIGrid(
    imagePath: string,
    cellWidth: number,
    cellHeight: number
): SpriteAtlas

Creates a SpriteAtlas from a grid of cells, mapping each quad to a UTF-8 character. The first quad is mapped to utf8.char(startingCode), e.g. ‘A’ for 65, ‘ ‘ for 32.

Parameters:
  • imagePath (string) – The path to the texture atlas image.

  • cellWidth (number) – The width of each cell in the grid.

  • cellHeight (number) – The height of each cell in the grid.

Returns:

_1 (SpriteAtlas) – The created SpriteAtlas instance.