Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(phaserx): avoid creating tilemap chunks if tilemap is not visible #241

Merged
merged 3 commits into from Nov 7, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages/phaserx/src/tilemap/createChunkedTilemap.ts
Expand Up @@ -122,7 +122,8 @@ export function createChunkedTilemap<TileKeys extends number, LayerKeys extends
return getMapAtChunkCoord(chunkCoord);
}

function destroyChunk(chunkCoord: WorldCoord) {
function destroyChunk(chunkCoord: WorldCoord, force?: boolean) {
if ((!visible.current && !force) || !maps.has(chunkCoord)) return;
const map = getMapAtChunkCoord(chunkCoord);
map.destroy();
maps.delete(chunkCoord);
Expand Down Expand Up @@ -185,7 +186,7 @@ export function createChunkedTilemap<TileKeys extends number, LayerKeys extends
if (v === visible.current) return;
visible.current = v;
for (const chunk of chunks.visibleChunks.current.coords()) {
visible.current ? renderChunk(chunk) : destroyChunk(chunk);
visible.current ? renderChunk(chunk) : destroyChunk(chunk, true);
}
}

Expand Down