diff options
author | phat_sumo <ethanjpayne1@gmail.com> | 2022-04-06 18:26:03 -0600 |
---|---|---|
committer | phat_sumo <ethanjpayne1@gmail.com> | 2022-04-06 18:26:03 -0600 |
commit | a54812ed50379bd8baacce53c16aeccdff752327 (patch) | |
tree | 3a4cb4e46a80f9c9091f79519822bfb1ca1a2f9f /src/render/graphics.js | |
parent | 66b29967e1a0c83c09da990fdb50e613a7e6caa0 (diff) | |
download | bbiy-a54812ed50379bd8baacce53c16aeccdff752327.tar.gz bbiy-a54812ed50379bd8baacce53c16aeccdff752327.zip |
convert hedge to grayscale, fix lava entity to use the new sprites, wordIs is pushable, dynamically color sprites
Diffstat (limited to 'src/render/graphics.js')
-rw-r--r-- | src/render/graphics.js | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/render/graphics.js b/src/render/graphics.js index 6a199f0..8a4cb1c 100644 --- a/src/render/graphics.js +++ b/src/render/graphics.js @@ -6,7 +6,7 @@ game.graphics = ( context.clearRect(0, 0, game.canvas.width, game.canvas.height); }; - const Sprite = ({image, spriteX, spriteY, spriteWidth, spriteHeight, timePerFrame, cols, rows, numFrames, drawFunction}) => { + const Sprite = ({image, spriteX, spriteY, spriteWidth, spriteHeight, timePerFrame, cols, rows, numFrames, color, drawFunction}) => { timePerFrame = timePerFrame ?? 100; numFrames = numFrames ?? 1; cols = cols ?? numFrames; @@ -33,6 +33,15 @@ game.graphics = ( const row = currentFrame % rows; const col = Math.floor(currentFrame / rows); context.drawImage(image, spriteX+col*spriteWidth, spriteY+row*spriteHeight, spriteWidth, spriteHeight, x, y, width, height); + + // apply color to sprite + if (color) { + context.globalAlpha=0.7; + context.globalCompositeOperation="source-atop"; + context.fillStyle=color; + context.fillRect(x, y, width, height); + } + context.restore(); }; } else { @@ -43,4 +52,4 @@ game.graphics = ( return { clear, Sprite }; } -)(document.getElementById("game-canvas").getContext("2d"));
\ No newline at end of file +)(document.getElementById("game-canvas").getContext("2d")); |