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: dynamic,
frameRate: integer,
playMode?: SpritePlayMode,
): BGE.SpriteAnimation
Parameters
name(string)frameList(dynamic)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
getCellDrawIndex(): integer
Returns
integer