UNPKG

pixelbutler

Version:

Low-res bitmap render engine for big screens

23 lines (22 loc) 685 B
'use strict'; var SpriteSheet = (function () { function SpriteSheet(width, height) { this.sprites = []; this.width = width; this.height = height; } SpriteSheet.prototype.getSprite = function (x, y) { return this.getSpriteAt(y * this.width + x); }; SpriteSheet.prototype.getSpriteAt = function (index) { if (this.sprites.length === 0) { throw new Error('sheet has zero images'); } return this.sprites[index % this.sprites.length]; }; SpriteSheet.prototype.addSprite = function (bitmap) { this.sprites.push(bitmap); }; return SpriteSheet; })(); module.exports = SpriteSheet;