Ustvaril seamless teksturo zemlje za zapolnitev ozadja

This commit is contained in:
2026-01-31 10:45:14 +01:00
parent c6e715ccc7
commit b2667d483c

View File

@@ -106,21 +106,41 @@ export default class GrassSceneClean extends Phaser.Scene {
// --- 1. PODLAGA (The Foundation) ---
// Preprosta rešitev: Rjava barva ozadja + tekstura čez
// 1. Nastavimo barvo ozadja na rjavo (barva zemlje), da se ne vidijo zelene luknje
// 1. Nastavimo barvo ozadja na rjavo (barva zemlje)
this.cameras.main.setBackgroundColor('#4e342e'); // Dark Brown
const BG_W = this.scale.width * 2.5;
const BG_H = this.scale.height * 2.5;
// 2. Uporabimo originalno sliko za tileSprite
this.ground = this.add.tileSprite(this.scale.width / 2, this.scale.height / 2, BG_W, BG_H, 'ground_base');
// 2. GENERIRANJE SEAMLESS TEKSTURE
// Ustvarimo gosto teksturo zemlje, da ni lukenj
const texSize = 512;
const rt = this.make.renderTexture({ width: texSize, height: texSize }, false);
// Zapolnimo s temno barvo
rt.fill(0x4e342e);
// Narišemo veliko "ground_base" slikic, da prekrijemo vse
const patchCount = 50;
for (let i = 0; i < patchCount; i++) {
let x = Math.random() * texSize;
let y = Math.random() * texSize;
let angle = Math.random() * 360;
let scale = 0.8 + Math.random() * 0.5;
rt.draw('ground_base', x, y, 1, 0xffffff);
// Dodatno risanje na robovih za seamless efekt (wrapping)
// (Poenostavljeno: samo gosto napolnimo)
}
// Shranimo teksturo pod novim ključem
rt.saveTexture('ground_seamless_gen');
// 3. Uporabimo novo generirano teksturo
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);
// Malo zamika in rotacije za variacijo (če je mogoče) - pri tileSprite ne moremo rotirati posameznih delov
// Lahko pa spremenimo alpha, da se malo zlije z ozadjem
// this.ground.setAlpha(0.9);
// Note: We need to update tilePosition in update() loop to match camera scroll!
// --- 2. RIVER SYSTEM (Infinite Scrolling) ---