A sprite sheet is a single image file that packs multiple animation frames into a grid of rows and columns. Instead of loading a separate image per frame, you load one file and tell Engine.js which region to display — advancing through columns automatically to produce animation. TheDocumentation 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 class holds all the information needed to slice that grid and advance frames at the right speed.
What Is a Sprite Sheet?
Imagine a run-cycle made of four frames, each 64 × 64 pixels, arranged side by side in one PNG. The full image is 256 × 64 px. Each frame occupies one column; all frames in this example live on row 0. Engine.js draws only the current column at any given moment, stepping to the next column after the per-frame interval elapses.The Sprite Class
| Parameter | Type | Description |
|---|---|---|
row | int | Which row of the sprite sheet to play (0-indexed) |
cols | int | Total number of columns (frames) in the sheet |
altura | number | Height of a single frame in pixels |
anchura | number | Width of a single frame in pixels |
velocidad | number | Total animation duration in seconds; internally converted to the per-frame interval |
Velocity Formula
The constructor converts the total animation duration into a per-frame interval using:velocidad is the total number of seconds you want the full animation cycle to last. The engine divides that evenly across all columns so each frame is displayed for the same duration.
Internal Frame State
EverySprite instance tracks its playback position with a frame object created in the constructor:
| Field | Description |
|---|---|
frame.valor | Current column index (starts at 0) |
frame.ultimo | Timestamp (ms) of the last frame advance (null until the first tick) |
frame manually — Engine.js manages it inside DibujarSprite on every render tick.
Using Sprites
Create a Sprite instance
Describe the layout of the sheet: which row to play, how many columns it has, the pixel size of each frame, and how long the full cycle should last.
Pass both to Imagen
Supply the
Image as the first argument and the Sprite as the second argument to $g.Imagen.Full Example
How Frame Advance Works
On every render tick, Engine.js callsDibujarSprite. It computes which region of the sprite sheet to show by multiplying the current column index by the frame width:
frame.valor reaches cols - 1, the modulo wraps it back to 0, creating a seamless loop.
Rendered Size for Sprite Figures
For sprite-based figures, Engine.js uses If you need a different on-screen size, set
Sprite.anchura and Sprite.altura as both the source clip size and the destination draw size — not Transform.anchura and Transform.altura. The same values are also used by tocandoFondo when calculating floor collision:Sprite.anchura and Sprite.altura to match your desired display dimensions.Next Steps
Static Images
Render a non-animated image with the
Imagen classSound
Add audio playback to figures with
SonidoAnimation Loop
How
IniciarAnimacion and DetenerAnimacion workSprite API
Full
Sprite API reference