SpriteFrames

The frames of a Sprite: which sheet bitmap and which rect each frame index draws from. Either a uniform grid (every cell cellWidth x cellHeight, numbered row by row, sheet after sheet), or packed frames of any size, each with its own rect, like a texture atlas.

Sprites made from the same SpriteFrames share its roRegions instead of each slicing the sheets again, which matters when many entities use one sheet. Game.getSpriteFrames() caches them by bitmap name, and Game.getSpriteAtlasFrames() gives a packed atlas's (loaded with AssetLoader.loadSpriteAtlas()).

Properties

  • sheets (Array.<ifDraw2d>) — Every sheet, in order
  • frames (Array.<BGE.SpriteFrameRect>) — Each frame's rect, with every optional field filled in
  • cellWidth (integer) — Grid cell size, or 0 for packed frames
  • cellHeight (integer)

Constructor

new SpriteFrames( sheets: ifDraw2d | Array.<ifDraw2d>, cellWidth: integer, cellHeight: integer, frameRects?: Array.<BGE.SpriteFrameRect>, ): SpriteFrames

Parameters

  • sheets (ifDraw2d | Array.<ifDraw2d>) — one sheet, or several
  • cellWidth (integer) — grid cell width; ignored when frameRects is given
  • cellHeight (integer) — grid cell height; ignored when frameRects is given
  • frameRects (Array.<BGE.SpriteFrameRect>, optional, default: "invalid") — packed frames, e.g. parsed from a JSON atlas

Instance Methods

isGrid(): boolean

Whether the frames are a uniform grid (rather than packed).

Returns

  • boolean

frameCount(): integer

Returns

  • integer

sheetIndexForFrame(frameIndex: integer): integer

Which sheet a frame is on, or -1 if it's out of range.

Parameters

  • frameIndex (integer)

Returns

  • integer

getMaxSourceSize(): BGE.Math.Vector

The largest untrimmed cell size of any frame, e.g. to size a drawable before it animates.

Returns

  • BGE.Math.Vector — x = width, y = height

getColumnTexture(frameIndex: integer): BGE.QuadColumnTexture

A frame's column texture for drawing it as projected columns, cut on first use and shared by every sprite drawing from these frames (column cuts don't depend on the anchor).

Parameters

  • frameIndex (integer)

Returns

regionsForAnchor( anchorX: float, anchorY: float, ): Array.<roRegion>

One region per frame, with the pretranslation for this anchor already set, so a frame trimmed out of its cell still draws where the untrimmed cell would. Built once per anchor and shared by every sprite asking for it: treat the regions as read-only.

Parameters

  • anchorX (float) — 0 (left) to 1 (right) of the untrimmed cell; 0 with no anchor
  • anchorY (float) — 0 (top) to 1 (bottom) of the untrimmed cell; 0 with no anchor

Returns

  • Array.<roRegion>