mwg API
    Preparing search index...

    Class SpriteSheet

    A texture cut into numbered frames.

    Nearly every sheet in a tile-based game is a regular grid, so grid covers the common case and name labels the frames that matter. Frames are cut once and cached: asking for the same index twice returns the same Texture, so sprites sharing a frame also share a texture and stay in one batch.

    The rest are not grids at all: a hand-packed icon atlas, a strip of bar segments, a nine-patch's corners. Those declare their own rectangles with rect, and the sheet is built with no frame size, which leaves it with no grid and only the frames declared.

    Index
    columns: number
    frameHeight: number
    frameWidth: number
    rows: number
    texture: Texture
    • gives a frame a name, so game code reads sheet.get('door') rather than sheet.get(6)

      Parameters

      • name: string
      • index: number

      Returns this

    • names several frames at once, from a plain object of name to index

      Parameters

      • names: Readonly<Record<string, number>>

      Returns this

    • specific frames, for an animation that holds or ping-pongs

      Parameters

      • ...frames: (string | number)[]

      Returns Texture<TextureSource<any>>[]

    • a run of consecutive frames, the usual way an animation is laid out

      Parameters

      • from: number
      • to: number

      Returns Texture<TextureSource<any>>[]

    • Cuts an arbitrary rectangle out of the texture, for a sheet that is not a grid: one hand-packed icon, two banner frames, the corners of a nine-patch.

      The rectangle is cached under index exactly like a grid frame, so get, region, name and pick all treat it as a frame and asking for it twice returns the same Texture rather than cutting a second one. Declaring a rect for an index the grid also covers replaces that frame, which is what a tightened sub-rect of a cell is: an item whose art is smaller than its 16 by 16 cell keeps its index and its name.

      Parameters

      • index: number
      • x: number
      • y: number
      • width: number
      • height: number

      Returns this

    • the texture and frame rectangle together, as plain MWG types rather than pixi.js's Texture/Rectangle - for a game that needs the geometry, not just the cut texture

      Parameters

      • frame: string | number

      Returns TextureRegion

    • Cuts a loaded texture into a grid, numbered left to right then top to bottom, or, with no frame size, leaves the sheet with no grid for rect to fill in.

      Parameters

      • path: string

        the asset path the texture was loaded with

      • frameWidth: number = 0
      • frameHeight: number = frameWidth

      Returns SpriteSheet