Skip to content

Commit

Permalink
Fix tile position during map generation
Browse files Browse the repository at this point in the history
  • Loading branch information
delasy committed Nov 5, 2024
1 parent 3daf553 commit adc4123
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions renderer/Background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export async function generateBg(
map: string[][],
cellSize = 64,
): Promise<HTMLImageElement> {
const tileSize = 64;
const floor = assets.floor;
const tileMap = assets.tileMap;

Expand All @@ -117,6 +118,10 @@ export async function generateBg(

for (let y = 0; y < map.length; y++) {
for (let x = 0; x < map[y].length; x++) {
if (map[y][x] !== "R") {
continue;
}

const bitMask = getBitMask(map, x, y);
const tileIdx = BITMASK_TO_TILE_INDEX[bitMask];

Expand All @@ -129,10 +134,10 @@ export async function generateBg(

ctx.drawImage(
tileMap,
sy * 64,
sx * 64,
64,
64,
sx * tileSize,
sy * tileSize,
tileSize,
tileSize,
x * cellSize,
y * cellSize,
cellSize,
Expand Down

0 comments on commit adc4123

Please sign in to comment.