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 tween = ref<Phaser.Tweens.Tween | null>(null)
|
||||||
|
|
||||||
const updateIsometricDepth = (positionX: number, positionY: number) => {
|
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) => {
|
const updatePosition = (positionX: number, positionY: number) => {
|
||||||
|
@ -63,32 +63,17 @@ export function createTileArray(width: number, height: number, tile: string = 'b
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const calculateIsometricDepth = (
|
export const calculateIsometricDepth = (
|
||||||
positionX: number,
|
positionX: number,
|
||||||
positionY: number,
|
positionY: number,
|
||||||
width: number = 0,
|
objectWidth: number = 0,
|
||||||
height: number = 0,
|
objectHeight: number = 0
|
||||||
originX: number = 0,
|
): number => {
|
||||||
originY: number = 0
|
const tileWidth = config.tile_size.width;
|
||||||
) => {
|
const tileHeight = config.tile_size.height;
|
||||||
// Base depth calculation using isometric coordinates
|
const tileSize = Math.max(tileWidth, tileHeight);
|
||||||
// We multiply by a large number to ensure enough space between layers
|
const objectSize = Math.max(objectWidth, objectHeight);
|
||||||
const baseDepth = (positionY + positionX) * 1000
|
return Math.floor(positionY * tileSize + positionX * objectSize);
|
||||||
|
};
|
||||||
// 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
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
async function loadTileTextures(tiles: TileT[], scene: Phaser.Scene) {
|
async function loadTileTextures(tiles: TileT[], scene: Phaser.Scene) {
|
||||||
// Load each tile into the scene
|
// Load each tile into the scene
|
||||||
|
Loading…
x
Reference in New Issue
Block a user