-
-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: TileMap packing + TileMap debug draw configurable (#2851)
This PR makes TileMap debug draw configurable, and by default reduces the draw burden by toggling off the grid display by default. This PR also fixes a tilemap packing bug where some situation would result in incorrect colliders https://github.com/excaliburjs/Excalibur/assets/612071/104bfb9d-c8e3-431e-a454-e8bed89ad960
- Loading branch information
Showing
10 changed files
with
281 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | ||
<title>TileMap Packing</title> | ||
</head> | ||
<body> | ||
<h1>TileMap Packing</h1> | ||
<p>Should collapse bounds into minimum geometry to represent colliders</p> | ||
<script src="../../lib/excalibur.js"></script> | ||
<script src="index.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/// <reference path='../../lib/excalibur.d.ts' /> | ||
|
||
var game = new ex.Engine({ | ||
width: 600, | ||
height: 600 | ||
}); | ||
|
||
game.toggleDebug(); | ||
game.debug.entity.showId = false; | ||
game.debug.tilemap.showSolidBounds = true; | ||
game.debug.tilemap.showGrid = true; | ||
|
||
var tm = new ex.TileMap({ | ||
pos: ex.vec(200, 200), | ||
tileWidth: 16, | ||
tileHeight: 16, | ||
columns: 6, | ||
rows: 4 | ||
}); | ||
|
||
tm.getTile(0, 0).solid = true; | ||
tm.getTile(0, 1).solid = true; | ||
tm.getTile(0, 2).solid = true; | ||
tm.getTile(0, 3).solid = true; | ||
|
||
tm.getTile(1, 0).solid = false; | ||
tm.getTile(1, 1).solid = false; | ||
tm.getTile(1, 2).solid = false; | ||
tm.getTile(1, 3).solid = false; | ||
|
||
tm.getTile(2, 0).solid = false; | ||
tm.getTile(2, 1).solid = false; | ||
tm.getTile(2, 2).solid = false; | ||
tm.getTile(2, 3).solid = false; | ||
|
||
tm.getTile(3, 0).solid = true; | ||
tm.getTile(3, 1).solid = true; | ||
tm.getTile(3, 2).solid = true; | ||
tm.getTile(3, 3).solid = true; | ||
|
||
tm.getTile(4, 0).solid = true; | ||
tm.getTile(4, 1).solid = true; | ||
tm.getTile(4, 2).solid = true; | ||
tm.getTile(4, 3).solid = true; | ||
|
||
game.add(tm); | ||
game.input.pointers.primary.on('down', (evt: ex.PointerEvent) => { | ||
const tile = tm.getTileByPoint(evt.worldPos); | ||
if (tile) { | ||
tile.solid = !tile.solid; | ||
} | ||
}); | ||
|
||
let currentPointer!: ex.Vector; | ||
game.input.pointers.primary.on('down', (moveEvent) => { | ||
if (moveEvent.button === ex.PointerButton.Right) { | ||
currentPointer = moveEvent.worldPos; | ||
game.currentScene.camera.move(currentPointer, 300, ex.EasingFunctions.EaseInOutCubic); | ||
} | ||
}); | ||
|
||
document.oncontextmenu = () => false; | ||
|
||
game.input.pointers.primary.on('wheel', (wheelEvent) => { | ||
// wheel up | ||
game.currentScene.camera.pos = currentPointer; | ||
if (wheelEvent.deltaY < 0) { | ||
game.currentScene.camera.zoom *= 1.2; | ||
} else { | ||
game.currentScene.camera.zoom /= 1.2; | ||
} | ||
}); | ||
|
||
game.start().then(() => { | ||
game.currentScene.camera.pos = ex.vec(250, 225); | ||
game.currentScene.camera.zoom = 3.5; | ||
currentPointer = game.currentScene.camera.pos; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.