MultiplayerMinesweeper/www/scripts/display/tileRenderer.js

25 lines
571 B
JavaScript

export var tileArray = loadSprites();
export function loadSprites() {
var tiles = [];
var spriteJank = document.getElementById('spriteJank');
var ctxj = spriteJank.getContext('2d');
var spriteSheet = new Image();
spriteSheet.src = '/sheet.png'
spriteSheet.onload = function() {
for (let y = 0; y < 16; y++) {
for (let x = 0; x < 16; x++) {
ctxj.drawImage(spriteSheet, -x*24,-y*24)
var tmp = new Image();
tmp.src = spriteJank.toDataURL();
ctxj.clearRect(0, 0, 24, 24);
tiles.push(tmp)
}
}
}
spriteJank.remove();
return tiles;
}