forked from noxious/client
Fixed depth sorting inside zone and zoneEditor
This commit is contained in:
@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user