ridder
Version:
A straightforward game engine for simple data-driven games in JavaScript
25 lines (24 loc) • 726 B
JavaScript
const sprites = [];
/**
* Load a sprite into the cache.
*
* Use `drawSprite` in the `render` function to draw the sprite onto the canvas.
*
* A sprite is a rectangular region within a texture.
*
* @param id - The ID for the sprite in the cache.
* @param textureId - The name of the texture in the cache.
* @param x - The x-coordinate of the sprite within the texture.
* @param y - The y-coordinate of the sprite within the texture.
* @param w - The width of the sprite.
* @param h - The height of the sprite.
*/
export function loadSprite(id, textureId, x, y, w, h) {
sprites[id] = { textureId, x, y, w, h };
}
/**
* Get a sprite from the cache.
*/
export function getSprite(id) {
return sprites[id];
}