import {game} from "../game/game.js" export const tileArray = loadSprites('/img/mine.png', game.tileSize); var counter = 0; export function loadSprites(path, tileSize) { let tiles = []; let spriteJank = document.createElement("canvas"); spriteJank.id = `spriteJank${counter}` spriteJank.style = "display: none;" spriteJank.width = tileSize; spriteJank.height = tileSize; document.body.appendChild(spriteJank); let ctxj = spriteJank.getContext('2d'); let spriteSheet = new Image(); spriteSheet.src = path spriteSheet.onload = function() { for (let y = 0; y < spriteSheet.height/tileSize; y++) { for (let x = 0; x < spriteSheet.width/tileSize; x++) { ctxj.drawImage(spriteSheet, -x*tileSize,-y*tileSize) var tmp = new Image(); tmp.src = spriteJank.toDataURL(); ctxj.clearRect(0, 0, tileSize, tileSize); tiles.push(tmp) } } } spriteJank.remove(); return tiles; } export const menuArray = loadSprites('/img/modes.png', 32)