diff --git a/src/core/utils.js b/src/core/utils.js index b3de6bb..15df479 100644 --- a/src/core/utils.js +++ b/src/core/utils.js @@ -123,9 +123,12 @@ export function getPixelFromChunkOffset( return [x, y]; } -export function getCellInsideChunk(pixel: Cell): Cell { +export function getCellInsideChunk( + canvasSize: number, + pixel: Cell, +): Cell { // TODO assert is positive! - return pixel.map((x) => mod(x, TILE_SIZE)); + return pixel.map((x) => mod(x + canvasSize / 2, TILE_SIZE)); } export function screenToWorld( diff --git a/src/ui/ChunkLoader2D.js b/src/ui/ChunkLoader2D.js index 2654442..4eef3a0 100644 --- a/src/ui/ChunkLoader2D.js +++ b/src/ui/ChunkLoader2D.js @@ -72,7 +72,7 @@ class ChunkLoader { return 0; } return chunk.getColorIndex( - getCellInsideChunk([x, y]), + getCellInsideChunk(canvasSize, [x, y]), ); }