DrawableOrientedSprite
Extends: Sprite
A Sprite that swaps which named animation is active based on the angle between the camera and this entity - the classic Doom/Duke3D "billboard sprite" technique for faking full 3D orientation with pre-rendered 2D views. See docs/drawables-and-scene-objects.md for a full walkthrough and specs/2026-09-22-oriented-sprite-billboards-design.md for the design.
Properties
numAngles(integer) — Number of horizontal (azimuth) view buckets around the entity. Bucket 0 is thenumElevationBands(integer) — Number of vertical (elevation) view bands, from the camera looking up at themirrorBuckets(boolean) — Halves the sheet for a roughly left/right-symmetric character: register only buckets 0lodDistance(float) — Animation level of detail: past this level distance (world units, across x/z) from the camera, an animationlodCheckSeconds(float) — How often (seconds) the distance is rechecked. After the first check (on the first
Constructor
new DrawableOrientedSprite(
owner: GameEntity,
spriteSheet: ifDraw2d | Array.<ifDraw2d> | BGE.SpriteFrames,
cellWidth: integer,
cellHeight: integer,
numAngles?: integer,
numElevationBands?: integer,
args?: roAssociativeArray,
): DrawableOrientedSpriteParameters
owner(GameEntity)spriteSheet(ifDraw2d | Array.<ifDraw2d> | BGE.SpriteFrames)cellWidth(integer)cellHeight(integer)numAngles(integer, optional, default: 8)numElevationBands(integer, optional, default: 1)args(roAssociativeArray, optional, default: "{}")
Instance Methods
addOrientedAnimation(
baseName: string,
angleFrames: Array.<Array.<integer>>,
frameRate: float,
playMode?: SpritePlayMode,
): void
Registers one animation per angle bucket under baseName (e.g. "walk"), for the single elevation band case (the common one - a sheet with no distinct top-down/ bottom-up art). Sugar for addElevationOrientedAnimation with a single-band wrapper; errors (via addElevationOrientedAnimation's own validation) if numElevationBands isn't actually 1.
Parameters
baseName(string)angleFrames(Array.<Array.<integer>>) — array of exactly numAngles entries (numAngles / 2 + 1 with mirrorBuckets), each an integer[] of frame indexes for that bucket's own art.frameRate(float)playMode(SpritePlayMode, optional, default: "SpritePlayMode.Loop")
Returns
void
addOrientedAnimationColumns(
baseName: string,
columns: Array.<integer>,
framesPerDirection: integer,
frameRate: float,
playMode?: SpritePlayMode,
): void
Registers baseName from frame columns shared by every angle bucket, for a sheet laid out one direction after another (bucket b's column c is frame b * framesPerDirection + c). Single elevation band only.
Parameters
baseName(string)columns(Array.<integer>) — frame columns within one direction, e.g. [4, 5, 6, 7] for a runframesPerDirection(integer) — frames each direction takes on the sheetframeRate(float)playMode(SpritePlayMode, optional, default: "SpritePlayMode.Loop")
Returns
void
framesForColumns(
columns: Array.<integer>,
framesPerDirection: integer,
): Array.<Array.<integer>>
The angleFrames array addOrientedAnimation takes, built from frame columns shared by every angle bucket (see addOrientedAnimationColumns()). Useful for building the tables once and sharing them between sprites.
Parameters
columns(Array.<integer>)framesPerDirection(integer)
Returns
Array.<Array.<integer>>— registeredAngleCount() entries of frame indexes
addElevationOrientedAnimation(
baseName: string,
elevationBands: Array.<Array.<Array.<integer>>>,
frameRate: float,
playMode?: SpritePlayMode,
): void
Registers the full elevation x angle grid under baseName. See specs/2026-09-22-oriented-sprite-billboards-design.md for the full bucket-index semantics.
Parameters
baseName(string)elevationBands(Array.<Array.<Array.<integer>>>) — array of exactly numElevationBands entries; each entry is itself an angleFrames array in the same shape addOrientedAnimation takes.frameRate(float)playMode(SpritePlayMode, optional, default: "SpritePlayMode.Loop")
Returns
void
registeredAngleCount(): integer
How many angle buckets each elevation band registers: numAngles, or with mirrorBuckets only front to back (numAngles / 2 + 1).
Returns
integer
isDrawingMirrored(): boolean
Whether the bucket currently showing is a mirrored copy of the other side (mirrorBuckets).
Returns
boolean
registeredAnimationNameForTests(
baseName: string,
elevationBand: integer,
angleBucket: integer,
): string
For tests only - the underlying Sprite animation name a bucket resolves to. Mirrors Sprite's own "for tests only" accessor convention (see rawAnimationClockMsForTests()).
Parameters
baseName(string)elevationBand(integer)angleBucket(integer)
Returns
string
getOrientedAnimationsDebugInfo(): roAssociativeArray
Debug helper - like Sprite.getAnimationsDebugInfo(), but grouped by baseName and (elevationBand, angleBucket) instead of raw internal Sprite animation names (e.g. "walk_e0_a3") - much easier to check "is the SE bucket for 'walk' really pointing at the sheet region I expect" than wading through synthesized names by hand. See logOrientedAnimationsDebugInfo() to print this as JSON instead of inspecting it directly.
Returns
roAssociativeArray
logOrientedAnimationsDebugInfo(): void
Prints getOrientedAnimationsDebugInfo() as JSON via this sprite's owner Game.log().
Returns
void
computeAngleBucket(
camera: BGE.Camera,
toCamera?: BGE.Math.Vector,
): integer
Computes which of numAngles horizontal view buckets is currently visible, from the angle between this entity's facing (rotation.y) and the direction from this entity to the camera. Bucket 0 = the entity's front is facing the camera; buckets increase clockwise as viewed from above. Always 0 for a camera that isn't a Camera3d (a 2D camera has no facing/orbit concept).
Parameters
camera(BGE.Camera)toCamera(BGE.Math.Vector, optional, default: "invalid") — the vector from the camera to this entity, if already computed this frame (e.g. by update()) - avoids recomputing it when both this and computeElevationBand() are called for the same camera/frame. Computed internally fromcamerawhen omitted.
Returns
integer
computeElevationBand(
camera: BGE.Camera,
toCamera?: BGE.Math.Vector,
): integer
Computes which of numElevationBands vertical view bands is currently visible, from the camera's pitch relative to this entity - band 0 is the camera below the entity looking up at it, band numElevationBands - 1 is the camera above looking down. Always 0 if numElevationBands is 1 (no vertical distinction requested) or the camera isn't a Camera3d.
Parameters
camera(BGE.Camera)toCamera(BGE.Math.Vector, optional, default: "invalid") — the vector from the camera to this entity, if already computed this frame (e.g. by update()) - avoids recomputing it when both this and computeAngleBucket() are called for the same camera/frame. Computed internally fromcamerawhen omitted.
Returns
integer
playOrientedAnimation(baseName: string, restart?: boolean): void
Selects which base animation is currently playing, analogous to Sprite. playAnimation - but this picks among the (numElevationBands x numAngles) per-bucket animations registered for baseName via addOrientedAnimation / addElevationOrientedAnimation, resolving which one to actually play every update() from the camera's angle to this entity. Replaying the baseName already playing keeps its place unless restart is true.
Parameters
baseName(string)restart(boolean, optional, default: false) — start from the first frame even if baseName is already playing
Returns
void
setLodAnimation(baseName: string, farBaseName: string): void
Past lodDistance, play farBaseName whenever baseName is playing. Both must be registered oriented animations. An empty farBaseName removes the stand-in.
Parameters
baseName(string) — e.g. "idle"farBaseName(string) — e.g. "still", a one-frame version of it
Returns
void
isLodFar(): boolean
Whether the last distance check found the camera past lodDistance (false with it off). Checks run in update() while an oriented animation plays.
Returns
boolean
update(): void
Returns
void