Generiranje goste teksture zemlje za zapolnitev ozadja

This commit is contained in:
2026-01-31 09:25:51 +01:00
parent d7196eaa82
commit 7bc7d901c5

View File

@@ -105,14 +105,47 @@ export default class GrassSceneClean extends Phaser.Scene {
});
// --- 1. PODLAGA (The Foundation) ---
// OPTIMIZATION: Instead of one massive 32000x32000 tileSprite which crashes WebGL,
// we use a smaller one that follows the camera (Infinite Scroll technique).
// Generiranje seamless teksture iz dirt patch-a
// Ustvarimo render texture, ki bo služila kot ozadje
const texSize = 512;
const rt = this.make.renderTexture({ width: texSize, height: texSize }, false);
// Size it to cover the screen even when zoomed out (0.5x zoom -> need 2x size)
// Narišemo 'ground_base' (dirt) večkrat, da pokrijemo luknje
// Ker je 'ground_base' verjetno izometričen/nepravilen, ga moramo "zložiti" skupaj
const patchSize = 128; // Predvidevamo velikost, prilagodimo
const rows = Math.ceil(texSize / patchSize) + 2;
const cols = Math.ceil(texSize / patchSize) + 2;
// Najprej temno rjava podlaga za vsak slučaj
rt.fill(0x3e2723);
for (let y = 0; y < rows; y++) {
for (let x = 0; x < cols; x++) {
let px = x * patchSize;
let py = y * patchSize;
// Stagger offset za boljšo pokritost
if (y % 2 !== 0) px -= patchSize / 2;
// Random variacija za naraven videz
let angle = Math.random() * 90 - 45; // Malo rotacije
let scale = 1.0 + Math.random() * 0.2; // Malo povečave
rt.draw('ground_base', px, py, 1.0, 0xFFFFFF); // Narišemo sprite
// Še en sloj zamaknjen za pol, da pokrije luknje
rt.draw('ground_base', px + patchSize/2, py + patchSize/2, 1.0, 0xCCCCCC); // Malo temnejši za globino
}
}
// Shranimo teksturo v cache pod novim ključem
rt.saveTexture('ground_seamless_gen');
// Uporabimo novo generirano teksturo za tileSprite
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 = this.add.tileSprite(this.scale.width / 2, this.scale.height / 2, BG_W, BG_H, 'ground_seamless_gen');
this.ground.setScrollFactor(0); // Sticks to camera
this.ground.setDepth(-100);