Y-based depth sorting for world objects (trees, buildings, rocks) #31

Closed
opened 2026-03-23 19:39:37 +00:00 by claude · 0 comments
Collaborator

Problem

All world objects use fixed depth values:

  • Stockpile zone: 4
  • Trees / rocks / seedlings: 5
  • Buildings (chest, bed, forester hut): 8

Because depth is fixed, draw order depends on spawn order instead of Y position. This causes visible glitches — e.g. a forester hut trunk drawn over the canopy of a tree on the tile below it.

Fix

Use tileY-based depth for all world objects so Phaser sorts them correctly:

  • ResourceSystem: sprite depth = tileY + 5, health bar depth = tileY + 6
  • TreeSeedlingSystem: sprite depth = tileY + 5
  • GameScene.renderPersistentObjects: building depth = tileY + 5 (chest, bed, forester hut); stockpile zone stays at 4
  • BuildingSystem: ghost + label moved to depth 1000/1001 so they always render on top

Result

Objects further down the screen (higher Y) correctly render in front of objects above them, regardless of spawn order.

## Problem All world objects use fixed depth values: - Stockpile zone: 4 - Trees / rocks / seedlings: 5 - Buildings (chest, bed, forester hut): 8 Because depth is fixed, draw order depends on spawn order instead of Y position. This causes visible glitches — e.g. a forester hut trunk drawn over the canopy of a tree on the tile below it. ## Fix Use `tileY`-based depth for all world objects so Phaser sorts them correctly: - `ResourceSystem`: sprite depth = `tileY + 5`, health bar depth = `tileY + 6` - `TreeSeedlingSystem`: sprite depth = `tileY + 5` - `GameScene.renderPersistentObjects`: building depth = `tileY + 5` (chest, bed, forester hut); stockpile zone stays at 4 - `BuildingSystem`: ghost + label moved to depth 1000/1001 so they always render on top ## Result Objects further down the screen (higher Y) correctly render in front of objects above them, regardless of spawn order.
tekki closed this issue 2026-03-23 20:07:29 +00:00
claude added the
bug
status: done
labels 2026-03-23 20:07:55 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: tekki/nissefolk#31
No description provided.