Skip to content
Snippets Groups Projects
Commit 1f26df1b authored by Elarouti Adam's avatar Elarouti Adam
Browse files

ca marche pas

parent 36c48fc8
Branches
No related tags found
No related merge requests found
...@@ -45,17 +45,31 @@ function drawPieces() { ...@@ -45,17 +45,31 @@ function drawPieces() {
for (let row = 0; row < 8; row++) { for (let row = 0; row < 8; row++) {
for (let col = 0; col < 8; col++) { for (let col = 0; col < 8; col++) {
const piece = board[row][col]; const piece = board[row][col];
if (piece !== "") {
let img = new Image(); let img = new Image();
img.src = "chess_pieces/" + pieceImages[piece]; if (piece !== ""){
img.onload = function () { drawPiece(piece,col,row)
ctx.drawImage(img, col * size, row * size, size, size);
};
} }
} }
} }
} }
function drawPiece(piece, col, row) {
let img = new Image();
img.src = "chess_pieces/" + pieceImages[piece];
img.onload = function () {
let tempCanvas = document.createElement("canvas");
let tempCtx = tempCanvas.getContext("2d");
tempCanvas.width = size;
tempCanvas.height = size;
// Dessiner l’image sur un canvas temporaire
tempCtx.drawImage(img, 0, 0, size, size);
// Ensuite, dessiner cette image sur le canvas principal
ctx.drawImage(tempCanvas, col * size, row * size, size, size);
};
}
// Fonction principale pour dessiner l'échiquier // Fonction principale pour dessiner l'échiquier
function draw() { function draw() {
drawBoard(); drawBoard();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment