diff options
author | munvoseli <muslinmelody@gmail.com> | 2023-06-10 10:11:16 -0400 |
---|---|---|
committer | munvoseli <muslinmelody@gmail.com> | 2023-06-10 10:11:16 -0400 |
commit | ec353f1ce4e6bf527694dacb806eafc1119c3c92 (patch) | |
tree | 34c35297d8e472effce267ebbd29913f7e0be391 | |
parent | 2fb2bc0cd9c1035d545c3ca4d6f3d0964d0a76c1 (diff) |
fix rendering with new walk animation
-rw-r--r-- | public/javascript/game.js | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/public/javascript/game.js b/public/javascript/game.js index 9140ade..a1a775a 100644 --- a/public/javascript/game.js +++ b/public/javascript/game.js @@ -1571,17 +1571,23 @@ function timerEvent() { cameraPos.y -= tempOffset; clearCanvas(); - var tempPos = new Pos(0, 0); - var tempOffset = new Pos(0, 0); - while (tempOffset.y < canvasSpriteSize) { - tempPos.set(cameraPos); - tempPos.add(tempOffset); - var tempTile = getTileBufferValue(tempPos); - drawTile(tempOffset, tempTile); - tempOffset.x += 1; - if (tempOffset.x >= canvasSpriteSize) { - tempOffset.x = 0; - tempOffset.y += 1; + { + const x0 = walkAnimDir == 1 ? -1 : 0; + const y0 = walkAnimDir == 2 ? -1 : 0; + const x2 = walkAnimDir == 3 ? canvasSpriteSize+1 : canvasSpriteSize; + const y2 = walkAnimDir == 0 ? canvasSpriteSize+1 : canvasSpriteSize; + let tempPos = new Pos(0, 0); + let tempOffset = new Pos(x0, y0); + while (tempOffset.y < y2) { + tempPos.set(cameraPos); + tempPos.add(tempOffset); + var tempTile = getTileBufferValue(tempPos); + drawTile(tempOffset, tempTile); + tempOffset.x += 1; + if (tempOffset.x >= x2) { + tempOffset.x = x0; + tempOffset.y += 1; + } } } var index = 0; |