From b23f7783476c087813e241e038b89396ce968865 Mon Sep 17 00:00:00 2001 From: DZ Date: Mon, 9 Mar 2026 14:20:01 -0700 Subject: [PATCH] fix: replace GeometryMask with alpha reveal, fix iso Y position bugs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Three bugs caused buildings to be invisible or mispositioned: 1. GeometryMask root cause: constructionMaskShape drew a rect with revealH=0 at progress=0, leaving the stencil buffer empty → bodyGraphic completely invisible. No fallback existed if the mask was never cleared before the first render frame. 2. visualRoot.y = 0 override: both the active-promotion guard and the updateConstruction() completion path set visualRoot.y = 0, wiping out the correct iso Y offset (isoPos.y - worldY) that updateRenderTransform() had just calculated. Off-diagonal buildings rendered at cartesian worldY instead of isometric isoPos.y. 3. Construction animation y: updateConstruction() used an absolute assignment (visualRoot.y = offset) which replaced the iso base position instead of adding to it. Fix: - Remove GeometryMask entirely (constructionMaskShape, constructionMask fields, setMask call, updateConstructionMask() method) - Use bodyGraphic.setAlpha(0→1) for the construction fade-in reveal - Change visualRoot.y slide-in to additive (+= offset) so it builds on top of the iso base position set by updateRenderTransform() - Remove all visualRoot.y = 0 overrides; let updateRenderTransform() own the base iso position every frame - Guard in update() now uses bodyGraphic.setAlpha(1) instead of clearMask() Result: buildings are always visible (alpha-based reveal, not stencil-based), positioned correctly at iso coordinates, with working construction animation. Co-Authored-By: Claude Sonnet 4.6 --- src/entities/Building.ts | 38 +++++++++----------------------------- 1 file changed, 9 insertions(+), 29 deletions(-) diff --git a/src/entities/Building.ts b/src/entities/Building.ts index 8553556..dafd81a 100644 --- a/src/entities/Building.ts +++ b/src/entities/Building.ts @@ -41,8 +41,6 @@ export class Building extends Phaser.GameObjects.Container { private selectionOutline: Phaser.GameObjects.Graphics private rallyLine: Phaser.GameObjects.Graphics private constructionOverlay: Phaser.GameObjects.Graphics - private constructionMaskShape: Phaser.GameObjects.Graphics - private constructionMask: Phaser.Display.Masks.GeometryMask private labelText: Phaser.GameObjects.Text private isSelected: boolean private factionColor: number @@ -86,7 +84,6 @@ export class Building extends Phaser.GameObjects.Container { this.selectionOutline = scene.add.graphics() this.rallyLine = scene.add.graphics() this.constructionOverlay = scene.add.graphics() - this.constructionMaskShape = scene.add.graphics().setAlpha(0) this.bodyGraphic = scene.add.graphics() this.healthBar = scene.add.graphics() this.labelText = scene.add.text(0, 0, '', { @@ -102,7 +99,6 @@ export class Building extends Phaser.GameObjects.Container { this.selectionOutline, this.rallyLine, this.constructionOverlay, - this.constructionMaskShape, this.bodyGraphic, this.healthBar, this.labelText, @@ -112,8 +108,6 @@ export class Building extends Phaser.GameObjects.Container { this.drawBody() this.drawHealthBar() this.drawSelectionOutline() - this.constructionMask = this.constructionMaskShape.createGeometryMask() - this.bodyGraphic.setMask(this.constructionMask) scene.add.existing(this) this.updateRenderTransform() @@ -205,15 +199,12 @@ export class Building extends Phaser.GameObjects.Container { } // State was externally promoted to 'active' (e.g. GameScene sets building.state = 'active' - // right after creation). The construction mask was never cleared, so bodyGraphic is invisible. - // Finalize construction visuals now. + // right after creation). Finalize construction visuals now. if (this.constructionProgress < 1) { this.constructionProgress = 1 this.setAlpha(1) - this.visualRoot.y = 0 - this.bodyGraphic.clearMask(false) + this.bodyGraphic.setAlpha(1) this.constructionOverlay.clear() - this.constructionMaskShape.clear() this.drawBody() } @@ -319,8 +310,7 @@ export class Building extends Phaser.GameObjects.Container { private playConstructionAnimation(): void { this.setAlpha(0.3) this.constructionProgress = 0 - this.visualRoot.y = 14 - this.updateConstructionMask() + this.bodyGraphic.setAlpha(0) this.drawConstructionOverlay() } @@ -328,16 +318,17 @@ export class Building extends Phaser.GameObjects.Container { const buildTime = this.def.stats.buildTime * 1000 || 100 this.constructionProgress = Math.min(1, this.constructionProgress + delta / buildTime) this.setAlpha(0.3 + this.constructionProgress * 0.7) - this.visualRoot.y = (1 - this.constructionProgress) * 14 - this.updateConstructionMask() + // Fade body in as construction progresses (alpha 0→1) + this.bodyGraphic.setAlpha(this.constructionProgress) + // Slide-in effect: ADD downward offset on top of the iso base position set by updateRenderTransform() + this.visualRoot.y += (1 - this.constructionProgress) * 14 this.drawConstructionOverlay() if (this.constructionProgress >= 1) { this.state = 'active' - this.visualRoot.y = 0 - this.bodyGraphic.clearMask(false) + // updateRenderTransform() already set the correct base position; don't override y + this.bodyGraphic.setAlpha(1) this.constructionOverlay.clear() - this.constructionMaskShape.clear() this.drawBody() this.emit('construction_complete', this) } @@ -357,17 +348,6 @@ export class Building extends Phaser.GameObjects.Container { ) } - private updateConstructionMask(): void { - const dims = this.getBoxDims() - const totalH = dims.wallH + dims.halfH * 2 + 10 - const totalW = dims.halfW * 2 + 10 - const revealH = totalH * this.constructionProgress - const bottomY = dims.baseY + dims.halfH + 5 - this.constructionMaskShape.clear() - this.constructionMaskShape.fillStyle(0xffffff, 1) - this.constructionMaskShape.fillRect(-totalW / 2, bottomY - revealH, totalW, revealH) - } - // ── Private: simple 3D box rendering ──────────────────────── /** Compute box dimensions from footprint size */