1
0
forked from noxious/client

fuck depth sorting man

This commit is contained in:
Dennis Postma 2025-02-13 17:08:47 +01:00
parent ddc26a021b
commit 579749f4e0
2 changed files with 12 additions and 27 deletions

View File

@ -18,7 +18,7 @@ export function useCharacterSpriteComposable(scene: Phaser.Scene, tilemap: Phase
const tween = ref<Phaser.Tweens.Tween | null>(null)
const updateIsometricDepth = (positionX: number, positionY: number) => {
isometricDepth.value = calculateIsometricDepth(positionX, positionY, 30, 95, true)
isometricDepth.value = calculateIsometricDepth(positionX, positionY, 30, 95)
}
const updatePosition = (positionX: number, positionY: number) => {

View File

@ -63,32 +63,17 @@ export function createTileArray(width: number, height: number, tile: string = 'b
}
export const calculateIsometricDepth = (
positionX: number,
positionY: number,
width: number = 0,
height: number = 0,
originX: number = 0,
originY: number = 0
) => {
// Base depth calculation using isometric coordinates
// We multiply by a large number to ensure enough space between layers
const baseDepth = (positionY + positionX) * 1000
// Calculate the object's bottom-most point considering its dimensions and origin
const bottomY = positionY + height - (height * originY)
const rightX = positionX + width - (width * originX)
// Add position-based offset to ensure objects further down and right appear on top
const positionOffset = (bottomY + rightX) * 10
// For regular objects, consider their size
// Larger objects should generally appear behind smaller ones at the same position
const sizeOffset = (width + height) * 5
// Final depth combines all factors
return baseDepth + positionOffset - sizeOffset
}
positionX: number,
positionY: number,
objectWidth: number = 0,
objectHeight: number = 0
): number => {
const tileWidth = config.tile_size.width;
const tileHeight = config.tile_size.height;
const tileSize = Math.max(tileWidth, tileHeight);
const objectSize = Math.max(objectWidth, objectHeight);
return Math.floor(positionY * tileSize + positionX * objectSize);
};
async function loadTileTextures(tiles: TileT[], scene: Phaser.Scene) {
// Load each tile into the scene