Documentation Index
Fetch the complete documentation index at: https://mintlify.com/OmarMtya/enginejs-module/llms.txt
Use this file to discover all available pages before exploring further.
Sprite configures how Engine.js slices and animates a sprite sheet attached to an Imagen. Each Sprite instance selects a single row of the sheet to play, specifies how many frames (columns) that row contains, the pixel dimensions of each frame, and the total desired loop duration. The engine’s DibujarSprite function reads these values every frame to decide which column to drawImage from the sheet.
Constructor
new Sprite(row, cols, altura, anchura, velocidad)
Zero-indexed row of the sprite sheet to play. Row
0 is the topmost strip.
The engine multiplies this value by altura to calculate the sy (source Y)
offset passed to drawImage.Total number of columns (frames) in the selected row. The current frame index
cycles from
0 to cols - 1 and then wraps back to 0.Height of a single frame in pixels. Used as both the source height in
drawImage and (by tocandoFondo()) as the collision floor boundary for
sprite figures.Width of a single frame in pixels. Used as the source width in
drawImage.Desired total animation loop duration in seconds. Internally converted to
a per-frame interval using:The resulting value is stored in
this.velocidad and compared against elapsed
time on each tick to decide whether to advance the frame index.Instance Properties
The row index, stored as an integer (
parseInt).The column count, stored as an integer (
parseInt).Frame height in pixels, stored as a float (
parseFloat).Frame width in pixels, stored as a float (
parseFloat).Computed per-frame interval in seconds. Derived from the constructor’s
velocidad argument; not the raw value you pass in.Internal animation state.
valor— current column index (0-based). The engine uses this as thesxmultiplier:sx = sprite.frame.valor * sprite.anchura.ultimo—Date.now()timestamp of the last frame advance, ornullbefore the first tick.
Frame Advance Logic
The engine advances the frame index when:When that condition is met,
sprite.frame.valor is incremented by 1 and
wrapped with modulo cols:sprite.frame.ultimo is then updated to Date.now(). This keeps the
animation rate consistent regardless of the canvas FPS.