Sprite
Extends: AnimatedImage
Properties
spriteSheet(ifDraw2d) — roBitmap to pick cells fromcellWidth(integer) — Width of each animation cell in the sprite image in pixelscellHeight(integer) — Height of each animation cell in the sprite image in pixelsanimations(roAssociativeArray) — Lookup map of animation name -> SpriteAnimation objectactiveAnimation(SpriteAnimation) — The current animation being played
Constructor
new Sprite(
owner: GameEntity,
spriteSheet: ifDraw2d,
cellWidth: integer,
cellHeight: integer,
args?: roAssociativeArray,
): SpriteParameters
owner(GameEntity)spriteSheet(ifDraw2d)cellWidth(integer)cellHeight(integer)args(roAssociativeArray, optional, default: "{}")
Instance Methods
applyPreTranslation(x: float, y: float): void
Apply a pre-translation to set the pivot point for the sprite cell
Parameters
x(float)y(float)
Returns
void
addAnimation(
name: string,
frameList: Array.<integer> | AnimationFrameDescription,
frameRate: integer,
playMode?: SpritePlayMode,
): BGE.SpriteAnimation
Parameters
name(string)frameList(Array.<integer> | AnimationFrameDescription)frameRate(integer)playMode(SpritePlayMode, optional, default: "SpritePlayMode.Loop")
Returns
playAnimation(animationName: string): void
Play an animation from the set of animations in this SpriteSheet. Calling this repeatedly with the same already-playing animationName (e.g. every onUpdate) is a no-op for timing purposes - only an actual switch to a different animation resets the animation clock, so a one-shot Forward/Reverse animation always starts at its first frame rather than reading whatever elapsed time built up while a previous animation was playing.
Parameters
animationName(string)
Returns
void
advanceAnimationClockForTests(ms: integer): void
For tests only - fast-forwards the animation clock without waiting in real time (mirrors GameTimer's own addTime()/removeTime() testing convention). Needed because animationTimer is protected on the AnimatedImage ancestor, which a spec class (not itself a BGE.Sprite subclass) can't reach directly.
Parameters
ms(integer)
Returns
void
rawAnimationClockMsForTests(): integer
For tests only - the raw elapsed milliseconds on the animation clock, unaffected by any animation's own duration/play-mode clamping (unlike getCellDrawIndex()'s already-clamped output). See advanceAnimationClockForTests() above.
Returns
integer
getAnimationsDebugInfo(): roAssociativeArray
Debug helper - a plain data snapshot of every animation registered via addAnimation(): its frame rate/play mode, and each frame's index plus the exact spritesheet pixel rect (x/y/width/height) it draws from. Use to sanity-check a spritesheet's cell layout/frame-index math against the actual art when an animation looks like it's drawing the wrong region - see logAnimationsDebugInfo() to print this as JSON instead of inspecting it directly.
Returns
roAssociativeArray
getFrameRegionDebugInfo(frameIndex: integer): roAssociativeArray
One frame's spritesheet pixel rect (x/y/width/height), or an error note if frameIndex is out of range for this sprite's own sliced regions. Factored out of getAnimationsDebugInfo() so it's independently callable too.
Parameters
frameIndex(integer)
Returns
roAssociativeArray
logAnimationsDebugInfo(): void
Prints getAnimationsDebugInfo() as JSON via this sprite's owner Game.log() - call from onCreate()/onInput()/a Rooibos test while chasing a spritesheet slicing bug, e.g. to compare a walk cycle's actual per-frame pixel rects against the sheet's real layout.
Returns
void
getCellDrawIndex(): integer
Returns
integer