Private
Public Access
1
0

fix texturen
All checks were successful
Dynamic Branch Deploy / build-and-deploy (push) Successful in 1m23s

This commit is contained in:
Sebastian Unterschütz
2025-12-04 23:21:01 +01:00
parent f97c05a278
commit ae3eb34c0e
2 changed files with 102 additions and 31 deletions

View File

@@ -4,44 +4,60 @@
// ========================================== // ==========================================
// 1. ASSETS LADEN (PIXI V8 KORREKT) // 1. ASSETS LADEN (PIXI V8 KORREKT)
// ========================================== // ==========================================
// ==========================================
// 1. ASSETS LADEN (FEHLERTOLERANT)
// ==========================================
async function loadAssets() { async function loadAssets() {
const keysToLoad = []; const assetsToLoad = [];
// A. Player hinzufügen // --- 1. REGISTRIEREN (Namen zu Pfaden zuordnen) ---
// A. Player
// Prüfen ob schon da, um Warnungen bei Hot-Reload zu vermeiden
if (!PIXI.Assets.cache.has('player')) {
PIXI.Assets.add({ alias: 'player', src: 'assets/player.png' }); PIXI.Assets.add({ alias: 'player', src: 'assets/player.png' });
keysToLoad.push('player'); assetsToLoad.push('player');
}
// B. Hintergründe aus Config // B. Hintergründe
if (gameConfig.backgrounds) { if (gameConfig.backgrounds) {
gameConfig.backgrounds.forEach(bg => { gameConfig.backgrounds.forEach(bg => {
// Alias = Dateiname (z.B. "school-background.jpg") if (!PIXI.Assets.cache.has(bg)) {
PIXI.Assets.add({ alias: bg, src: 'assets/' + bg }); PIXI.Assets.add({ alias: bg, src: 'assets/' + bg });
keysToLoad.push(bg); assetsToLoad.push(bg);
}
}); });
} }
// C. Hindernisse aus Config // C. Hindernisse
if (gameConfig.obstacles) { if (gameConfig.obstacles) {
gameConfig.obstacles.forEach(def => { gameConfig.obstacles.forEach(def => {
if (def.image) { if (def.image && !PIXI.Assets.cache.has(def.id)) {
// Alias = ID (z.B. "teacher")
// Checken ob Alias schon existiert (vermeidet Warnungen)
if (!PIXI.Assets.cache.has(def.id)) {
PIXI.Assets.add({ alias: def.id, src: 'assets/' + def.image }); PIXI.Assets.add({ alias: def.id, src: 'assets/' + def.image });
keysToLoad.push(def.id); assetsToLoad.push(def.id);
}
} }
}); });
} }
try { // --- 2. LADEN (Mit Fehler-Abfangung) ---
console.log("Lade Assets...", keysToLoad); console.log(`Lade ${assetsToLoad.length} Assets...`);
// Alles auf einmal laden
await PIXI.Assets.load(keysToLoad); // Wir erstellen für jedes Asset einen eigenen Lade-Versuch
console.log("✅ Alle Texturen geladen!"); const loadPromises = assetsToLoad.map(key => {
} catch (e) { return PIXI.Assets.load(key)
console.error("❌ Asset Fehler:", e); .catch(err => {
} // HIER IST DER TRICK:
// Wenn ein Fehler passiert, loggen wir ihn, aber werfen ihn NICHT weiter.
// Wir geben einfach null zurück. Damit gilt dieser Task als "erledigt".
console.warn(`⚠️ Asset Fehler bei '${key}': Datei fehlt oder defekt.`);
return null;
});
});
// Wir warten, bis ALLE Versuche durch sind (egal ob Erfolg oder Fehler)
await Promise.all(loadPromises);
console.log("✅ Ladevorgang abgeschlossen (vorhandene Assets sind bereit).");
} }
// ... (Rest der Datei: startGameClick, gameLoop etc. BLEIBT GLEICH) // ... (Rest der Datei: startGameClick, gameLoop etc. BLEIBT GLEICH)

View File

@@ -116,20 +116,37 @@ function syncSprites(dataList, cacheMap, type, alpha) {
usedObjects.add(obj); usedObjects.add(obj);
let sprite = cacheMap.get(obj); let sprite = cacheMap.get(obj);
// A. Erstellen (wenn neu)
if (!sprite) { if (!sprite) {
sprite = createPixiSprite(obj, type); sprite = createPixiSprite(obj, type);
gameLayer.addChild(sprite); gameLayer.addChild(sprite);
cacheMap.set(obj, sprite); cacheMap.set(obj, sprite);
} }
// B. Updaten (Interpolation)
const def = obj.def || {}; const def = obj.def || {};
// Position interpolieren
const rX = (obj.prevX !== undefined) ? lerp(obj.prevX, obj.x, alpha) : obj.x; const rX = (obj.prevX !== undefined) ? lerp(obj.prevX, obj.x, alpha) : obj.x;
const rY = obj.y; const rY = obj.y;
if (obj.speech) {
let bubble = sprite.children.find(c => c.label === "bubble");
if (!bubble) {
bubble = createSpeechBubble(obj.speech);
bubble.y = -10;
if (def.height) bubble.y = -5;
sprite.addChild(bubble);
}
} else {
// Keine Sprache mehr? Blase entfernen falls vorhanden
const bubble = sprite.children.find(c => c.label === "bubble");
if (bubble) {
sprite.removeChild(bubble);
bubble.destroy();
}
}
if (type === 'platform') { if (type === 'platform') {
sprite.x = rX; sprite.x = rX;
sprite.y = rY; sprite.y = rY;
@@ -265,3 +282,41 @@ function drawDebugOverlay(alpha) {
g.rect(rX, o.y, def.width||30, def.height||30).stroke({ width: 1, color: 0x00FF00 }); g.rect(rX, o.y, def.width||30, def.height||30).stroke({ width: 1, color: 0x00FF00 });
}); });
} }
// Helper: Erstellt eine Pixi-Sprechblase
function createSpeechBubble(text) {
const container = new PIXI.Container();
// 1. Text erstellen
const style = new PIXI.TextStyle({
fontFamily: 'monospace',
fontSize: 12,
fontWeight: 'bold',
fill: '#000000',
align: 'center'
});
const pixiText = new PIXI.Text({ text: text, style: style });
pixiText.anchor.set(0.5); // Text-Mitte ist Anker
// Maße berechnen
const w = pixiText.width + 10;
const h = pixiText.height + 6;
// 2. Hintergrund (Blase)
const g = new PIXI.Graphics();
g.rect(-w/2, -h/2, w, h).fill(0xFFFFFF); // Weißer Kasten
g.rect(-w/2, -h/2, w, h).stroke({ width: 2, color: 0x000000 }); // Schwarzer Rand
// Kleines Dreieck unten (optional, für den "Speech"-Look)
g.moveTo(-5, h/2).lineTo(0, h/2 + 5).lineTo(5, h/2).fill(0xFFFFFF);
// Zusammenfügen
container.addChild(g);
container.addChild(pixiText);
// Name setzen, damit wir es später wiederfinden
container.label = "bubble";
return container;
}