Skip to content

Commit

Permalink
Fix off-by-one error when creating buckets
Browse files Browse the repository at this point in the history
  • Loading branch information
aznhassan committed Jul 12, 2024
1 parent e9971b2 commit 17bead5
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions libs/game/spritemap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,15 @@ namespace sprites {

const tMap = game.currentScene().tileMap;

// TODO: If we are not using a tile map, the number of buckets is based on the screen size
// Anything outside the screen is but into one giant bucket
const areaWidth = tMap ? tMap.areaWidth() : screen.width;
const areaHeight = tMap ? tMap.areaHeight() : screen.height;

this.cellWidth = Math.clamp(8, areaWidth >> 2, maxWidth * 2);
this.cellHeight = Math.clamp(8, areaHeight >> 2, maxHeight * 2);
this.rowCount = Math.idiv(areaHeight, this.cellHeight);
this.columnCount = Math.idiv(areaWidth, this.cellWidth);
this.rowCount = Math.ceil(areaHeight / this.cellHeight);
this.columnCount = Math.ceil(areaWidth / this.cellWidth);
}

/**
Expand Down

0 comments on commit 17bead5

Please sign in to comment.