forked from noxious/client
fuck depth sorting man
This commit is contained in:
parent
ddc26a021b
commit
579749f4e0
@ -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) => {
|
||||
|
@ -65,30 +65,15 @@ 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
|
||||
}
|
||||
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user