Fix black screen: Optimize massive ground using Infinite Scroll technique
This commit is contained in:
@@ -104,10 +104,18 @@ export default class GrassSceneClean extends Phaser.Scene {
|
||||
});
|
||||
|
||||
// --- 1. PODLAGA (The Foundation) ---
|
||||
// Level 0, Locked to Z = -100
|
||||
this.ground = this.add.tileSprite(WORLD_W / 2, WORLD_H / 2, WORLD_W, WORLD_H, 'ground_base');
|
||||
this.ground.setTileScale(1, 1);
|
||||
// OPTIMIZATION: Instead of one massive 32000x32000 tileSprite which crashes WebGL,
|
||||
// we use a smaller one that follows the camera (Infinite Scroll technique).
|
||||
|
||||
// Size it to cover the screen even when zoomed out (0.5x zoom -> need 2x size)
|
||||
const BG_W = this.scale.width * 2.5;
|
||||
const BG_H = this.scale.height * 2.5;
|
||||
|
||||
this.ground = this.add.tileSprite(this.scale.width / 2, this.scale.height / 2, BG_W, BG_H, 'ground_base');
|
||||
this.ground.setScrollFactor(0); // Sticks to camera
|
||||
this.ground.setDepth(-100);
|
||||
|
||||
// Note: We need to update tilePosition in update() loop to match camera scroll!
|
||||
|
||||
// --- 2. STREAM SYSTEM (Head + Extensions) ---
|
||||
// REMOVED PER USER REQUEST (Clean Start)
|
||||
@@ -717,6 +725,15 @@ export default class GrassSceneClean extends Phaser.Scene {
|
||||
}
|
||||
|
||||
update() {
|
||||
// --- GROUND INFINITE SCROLL ---
|
||||
if (this.ground) {
|
||||
this.ground.tilePositionX = this.cameras.main.scrollX;
|
||||
this.ground.tilePositionY = this.cameras.main.scrollY;
|
||||
// Also need to move the sprite itself to stay centered on camera
|
||||
this.ground.x = this.cameras.main.scrollX + this.scale.width / 2;
|
||||
this.ground.y = this.cameras.main.scrollY + this.scale.height / 2;
|
||||
}
|
||||
|
||||
// --- FOG MOVEMENT ---
|
||||
/*
|
||||
if (this.fog1) {
|
||||
|
||||
Reference in New Issue
Block a user