1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
| let canvas = document.getElementById("render"); let ctx = canvas.getContext("2d");
let imgs = {}; function draw() { let role = imgs["img.png"]; let map = imgs["0.png"];
ctx.fillStyle = "#ffffff";
ctx.fillRect(0, 0, 244, 235); ctx.drawImage(map, 0, 0);
ctx.globalAlpha = .5; ctx.globalCompositeOperation = "xor"; ctx.drawImage(role, 5, 60);
ctx.globalAlpha = 1; ctx.fillStyle = "#000000"; ctx.globalCompositeOperation = "destination-atop"; ctx.fillRect(0, 0, 244, 230);
ctx.globalAlpha = 1; ctx.globalCompositeOperation = "xor"; ctx.drawImage(role, 144, 60);
ctx.globalAlpha = 1; ctx.fillStyle = "#ff0000"; ctx.globalCompositeOperation = "destination-atop"; ctx.fillRect(0, 0, 244, 230);
ctx.fillStyle = "#ffffff"; ctx.globalCompositeOperation = "source-over"; ctx.drawImage(role, 72, 60); }
var count = 0; let res = ["0.png", "img.png"]; for (let f of res) { let img = new Image(); img.onload = function (e) { imgs[f] = img; count += 1; if (count >= res.length) draw(); } img.src = f; }
|