LittleJS 1.30.0

Draw

SpriteAnimation

SpriteAnimation - Steps a tile through its frames over time: looping, once, or there and back

  • Driven by the engine time like a Timer, so it pauses with the game and needs no update call
  • Read tileInfo each frame for the frame to draw, from an object's update or before a drawTile
  • loop, play and pingPong each start over from the first frame; stop holds the current one
  • play(onEnd) calls onEnd once the play ends, on the first read after it, since there is no update to call it
  • Frames follow each other along the row and on into the next row of the sheet, as tileInfo.frame counts them
  • SpriteAnimator switches between a character's animations by name

Constructor

new SpriteAnimation(tileInfo, frameCount, frameTime)engineDraw.js:419

Create an animation over a run of frames, looping from the start

tileInfo TileInfo

The first frame

frameCount number

How many frames, one or more

frameTime number optional, default 0.1

Seconds each frame shows for

const walk = new SpriteAnimation(tile(0, 16), 4, .1); // four frames, a tenth of a second each
const attack = new SpriteAnimation(tile(4, 16), 3, .05).play(); // once, then holds the last frame
// in update: this.tileInfo = (attack.isDone ? walk : attack).tileInfo;

Members

Methods

Members

elapsedFrames : numberengineDraw.js:486

How many frames have gone by since the start, fractional

The first frame, the others follow it as tileInfo.frame counts them

frame : numberengineDraw.js:490

The frame showing now, 0 to frameCount-1

frameCount : numberengineDraw.js:432

How many frames

frameTime : numberengineDraw.js:434

Seconds each frame shows for

heldFrame : number|undefinedengineDraw.js:444

The frame held by stop, undefined while running

isDone : booleanengineDraw.js:510

True once a play has shown its last frame for its time, the first read after that calls onEnd

mode : 'loop'|'once'|'pingPong'engineDraw.js:439

How it runs, set by loop, play and pingPong

Called once when a play ends, on the first read after it

speed : numberengineDraw.js:436

Rate multiplier, 2 plays twice as fast; set it before starting

startTime : numberengineDraw.js:441

Engine time it started at

The tile of the frame showing now

Methods

Start over from the first frame and repeat forever

Start over from the first frame and run there and back forever

Start over from the first frame, run through once and hold the last frame, last to first at a negative speed

onEnd function optional

Called once when it ends, on the first read of it after that

Start over from the first frame in a mode, with no end callback

mode 'loop'|'once'|'pingPong' optional

The current mode when left out

Hold the current frame