MultiplayerMinesweeper/www/scripts/display/tileRenderer.js

29 lines
744 B
JavaScript
Raw Normal View History

2022-06-21 14:46:34 +00:00
import {game} from "/scripts/game/game.js"
2022-06-19 21:54:34 +00:00
export var tileArray = loadSprites();
export function loadSprites() {
var tiles = [];
var spriteJank = document.getElementById('spriteJank');
2022-06-21 14:46:34 +00:00
spriteJank.width = game.tileSize;
spriteJank.height = game.tileSize;
2022-06-19 21:54:34 +00:00
var ctxj = spriteJank.getContext('2d');
var spriteSheet = new Image();
2022-06-21 14:46:34 +00:00
spriteSheet.src = '/mine.png'
2022-06-19 21:54:34 +00:00
spriteSheet.onload = function() {
2022-06-21 14:46:34 +00:00
const tileSize = game.tileSize;
for (let y = 0; y < 8; y++) {
for (let x = 0; x < 8; x++) {
ctxj.drawImage(spriteSheet, -x*tileSize,-y*tileSize)
2022-06-19 21:54:34 +00:00
var tmp = new Image();
tmp.src = spriteJank.toDataURL();
2022-06-21 14:46:34 +00:00
ctxj.clearRect(0, 0, tileSize, tileSize);
2022-06-19 21:54:34 +00:00
tiles.push(tmp)
}
}
}
spriteJank.remove();
return tiles;
}