Skip to content

Commit a5f2e09

Browse files
authored
Merge pull request #19 from MVPFlow/codex/fix-parallax-background-visibility-issues
fix: make desert visible and use single top cloud layer
2 parents 54a30e0 + a10f405 commit a5f2e09

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

‎src/scenes/GameScene.ts‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const BASE_SPAWN_INTERVAL = 900;
2222
const MIN_SPAWN_INTERVAL = 320;
2323
const COIN_CHANCE = 0.22;
2424
const COIN_SCALE = 0.55;
25-
const CLOUD_SCROLL_SPEED = 0.02;
25+
const CLOUD_SCROLL_SPEED = 0.006;
2626
const BASE_BG_COLOR = 0x9fd7ff;
2727

2828
export class GameScene extends Phaser.Scene {
@@ -222,7 +222,17 @@ export class GameScene extends Phaser.Scene {
222222
this.baseColor.setSize(width, height);
223223
this.baseColor.setDisplaySize(width, height);
224224
this.desertBackground.setDisplaySize(width, height);
225-
this.cloudLayer.setSize(width, height);
226-
this.cloudLayer.setDisplaySize(width, height);
225+
const cloudHeight = this.getCloudBandHeight(height);
226+
this.cloudLayer.setPosition(0, 0);
227+
this.cloudLayer.setSize(width, cloudHeight);
228+
this.cloudLayer.setDisplaySize(width, cloudHeight);
229+
}
230+
231+
private getCloudBandHeight(viewportHeight: number) {
232+
const texture = this.textures.get(KENNEY_BG_CLOUDS);
233+
const source = texture.getSourceImage() as HTMLImageElement | HTMLCanvasElement | HTMLVideoElement;
234+
const textureHeight = source?.height ?? viewportHeight;
235+
const desiredHeight = Math.floor(viewportHeight * 0.25);
236+
return Math.max(1, Math.min(desiredHeight, textureHeight));
227237
}
228238
}

0 commit comments

Comments
 (0)