1
0
forked from noxious/client

Fixed depth sorting inside zone and zoneEditor

This commit is contained in:
2024-09-15 18:22:54 +02:00
parent 4be606778c
commit e8a0b0f13d
4 changed files with 72 additions and 9 deletions

View File

@ -97,6 +97,22 @@ export const updateZoneTiles = (zoneTilemap: Tilemap, tiles: Phaser.Tilemaps.Til
return []
}
export const calculateIsometricDepth = (x: number, y: number, height: number = 0) => {
// Adjust these values as needed for your specific isometric projection
const isoX = x - y;
const isoY = (x + y) / 2;
return isoY - height * 0.1; // Subtract height to make taller objects appear behind shorter ones
}
export const sortByIsometricDepth = <T extends { positionX: number; positionY: number; object?: { height?: number } }>(items: T[]) => {
return [...items].sort((a, b) => {
const aHeight = a.object?.height || 0;
const bHeight = b.object?.height || 0;
return calculateIsometricDepth(a.positionX, a.positionY, aHeight) - calculateIsometricDepth(b.positionX, b.positionY, bHeight);
});
}
// Redundant, but left here for reference
export const calculateDepth = (x: number, y: number, mapWidth: number) => {
return y * mapWidth + x
}