diff --git a/CHANGELOG.md b/CHANGELOG.md index b5fd6ccb8..0c44792c0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/sandbox/tests/tilemap-pack/index.ts b/sandbox/tests/tilemap-pack/index.ts index d142fb0e2..93b43235b 100644 --- a/sandbox/tests/tilemap-pack/index.ts +++ b/sandbox/tests/tilemap-pack/index.ts @@ -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; diff --git a/src/engine/TileMap/TileMap.ts b/src/engine/TileMap/TileMap.ts index 992d5bb86..fad270e6a 100644 --- a/src/engine/TileMap/TileMap.ts +++ b/src/engine/TileMap/TileMap.ts @@ -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 & { @@ -87,6 +97,7 @@ export class TileMap extends Entity { public readonly columns: number; public renderFromTopOfGraphic = false; + public meshingLookBehind = 10; private _collidersDirty = true; public flagCollidersDirty() { @@ -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( @@ -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; }