Skip to content

Commit

Permalink
feat: Allow Tilemap meshing to be configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
eonarheim committed Feb 8, 2024
1 parent a6e666f commit 9449d94
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).

### Added

- Added configuration option to `ex.TileMap({ meshingLookBehind: Infinity })` which allows users to configure how far the TileMap looks behind for matching colliders (default is 10).
- Added Arcade Collision Solver bias to help mitigate seams in geometry that can cause problems for certain games.
- `ex.ContactSolveBias.None` No bias, current default behavior collisions are solved in the default distance order
- `ex.ContactSolveBias.VerticalFirst` Vertical collisions are solved first (useful for platformers with up/down gravity)
Expand Down
9 changes: 5 additions & 4 deletions sandbox/tests/tilemap-pack/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ var game = new ex.Engine({

game.toggleDebug();
game.debug.entity.showId = false;
game.debug.tilemap.showSolidBounds = true;
game.debug.tilemap.showGrid = true;
game.debug.tilemap.showSolidBounds = false;
// game.debug.tilemap.showGrid = true;

var tm = new ex.TileMap({
pos: ex.vec(200, 200),
tileWidth: 16,
tileHeight: 16,
columns: 6,
rows: 4
columns: 60,
rows: 60,
meshingLookBehind: Infinity
});

tm.getTile(0, 0).solid = true;
Expand Down
14 changes: 13 additions & 1 deletion src/engine/TileMap/TileMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ export interface TileMapOptions {
* Optionally render from the top of the graphic, by default tiles are rendered from the bottom
*/
renderFromTopOfGraphic?: boolean;

/**
* Optionally configure the meshing lookbehind for Tilemap, Tilemaps combine solid tiles into optimal
* geometry and the lookbehind configures how far back the Tilemap to look for geometry when combining. Meshing
* is an expensive operation, so when the Tilemap geometry is invalidated it must be recalculated.
*
* Default is 10 slots, but if your Tilemap does not change positions or solid tiles often you can increase this to
* Infinity.
*/
meshingLookBehind?: number;
}

export type TileMapEvents = EntityEvents & {
Expand Down Expand Up @@ -87,6 +97,7 @@ export class TileMap extends Entity {
public readonly columns: number;

public renderFromTopOfGraphic = false;
public meshingLookBehind = 10;

private _collidersDirty = true;
public flagCollidersDirty() {
Expand Down Expand Up @@ -207,6 +218,7 @@ export class TileMap extends Entity {
*/
constructor(options: TileMapOptions) {
super([], options.name);
this.meshingLookBehind = options.meshingLookBehind ?? this.meshingLookBehind;
this.addComponent(new TransformComponent());
this.addComponent(new MotionComponent());
this.addComponent(
Expand Down Expand Up @@ -338,7 +350,7 @@ export class TileMap extends Entity {
* @param maxLookBack The amount of colliders to look back for combination
* @returns false when no combination found, true when successfully combined
*/
const checkAndCombine = (current: BoundingBox, colliders: BoundingBox[], maxLookBack = 10) => {
const checkAndCombine = (current: BoundingBox, colliders: BoundingBox[], maxLookBack = this.meshingLookBehind) => {
if (!current) {
return false;
}
Expand Down

0 comments on commit 9449d94

Please sign in to comment.