Pixi’VN
Interfaccia utente (UI)JavaScript Frameworks

React UI

Come integrare Pixi’VN con React, inclusi configurazione, template e le migliori librerie UI. Crea una visual novel o un gioco narrativo con React.

Pixi’VN funziona benissimo come motore visual novel React, permettendoti di creare l'interfaccia utente della tua visual novel o gioco narrativo con i componenti React, mentre Pixi’VN gestisce la narrazione e il canvas.

Cos'è React? React è una libreria JavaScript per la creazione di interfacce utente (UI) per siti web, app e altro ancora. È gratuito, open source ed è mantenuto da Meta (già Facebook) e da una vasta comunità.

Puoi saperne di più su React sul sito web di React.

Come aggiungere Pixi’VN a un'applicazione React

Modelli

Sono disponibili template di Pixi’VN che utilizzano React. Puoi saperne di più su di essi nella sezione template.Se vuoi aggiungere Pixi’VN a un'applicazione React esistente, segui i passaggi seguenti.

Se vuoi aggiungere Pixi’VN a un'applicazione React esistente, segui i passaggi seguenti.

Prima di tutto, hai bisogno di un'applicazione React e di installare pixi-vn. Si consiglia di utilizzare Vite per creare una nuova applicazione React.

Ora puoi sostituire il contenuto dei seguenti file con il codice qui sotto:

import { Assets, canvas, Container, drawCanvasErrorHandler, Game, showImage, sound } from "@drincs/pixi-vn"; 
import { StrictMode } from "react";
import { createRoot } from "react-dom/client";
import App from "./App.tsx";
import "./index.css";

createRoot(document.getElementById("root")!).render( 
const body = document.body; 
if (!body) { 
    throw new Error("body element not found"); 
} 

Game.init(body, { 
    height: 1080, 
    width: 1920, 
    backgroundColor: "#303030", 
    resizeMode: "contain", 
}).then(() => { 
    showImage( 
        "juliette", 
        "https://raw.githubusercontent.com/DRincs-Productions/pixi-vn-bucket/refs/heads/main/icon.webp", 
        { xAlign: 0.9, yAlign: 0.1, anchor: 0.5 }, 
    ).then(() => { 
        canvas.animate("juliette", { angle: 360 }, { repeat: Infinity, duration: 5 }); 
    }); 

    // Pixi.JS UI Layer
    canvas.layers.add("ui", new Container()); 

    // Sound setup
    sound.channels.add("bgm", { background: true }); 
    sound.channels.add("sfx"); 
    sound.defaultChannelAlias = "sfx"; 

    // React setup with ReactDOM
    const root = document.getElementById("root"); 
    if (!root) { 
        throw new Error("root element not found"); 
    } 

    const htmlLayout = canvas.htmlLayers.add("ui", root); 
    if (!htmlLayout) { 
        throw new Error("htmlLayout not found"); 
    } 
    const reactRoot = createRoot(htmlLayout); 

    reactRoot.render(
        <StrictMode>
            <App />
        </StrictMode>,
    )
}); 

Game.onEnd(async (props) => { 
    Game.clear(); 
    // Navigate to the main menu after the game ends
}); 

Game.addOnError(drawCanvasErrorHandler()); 
Game.addOnError((error, props) => { 
    console.error(`Error occurred`, error); 
}); 

Game.onLoadingLabel((_stepId, { id }) => Assets.backgroundLoadBundle(id)); 

In questa pagina