Phaser
← Bring content into your game
Phaser 3.90 · JavaScript
Start with one visible sentence. This small example reads the real Harbour export directly; it is not a complete dialogue player. Then connect the data to your game UI.
1 · Prepare files and scene
Create index.html, first-text.js and story/story.json in one web project. Include Phaser 3.90 before first-text.js using script tags. You can use the existing examples/phaser/phaser.min.js file. Open the project through a local web server, not by double-clicking HTML.
story.json · Export files explained
2 · Show the first text
<!doctype html>
<html lang="en"><meta charset="utf-8"><title>First VNLE text</title>
<script src="phaser.min.js"></script>
<script src="first-text.js"></script></html>class FirstText extends Phaser.Scene {
preload() {
this.load.json('story', 'story/story.json');
this.load.on('loaderror', file => console.error('Cannot load', file.src));
}
create() {
const story = this.cache.json.get('story');
if (!story) { this.add.text(24, 24, 'Cannot load story.json'); return; }
const locale = 'en';
const id = 'fd7b61a3-8233-4ba7-8f77-b88b119a91bf';
const record = story.content.texts[id];
const translation = story.content.translations[locale]?.[id];
const message = translation ? translation.message : record.sourceMessage;
const text = message.segments.map(segment => {
if (segment.kind !== 'text') throw new Error('Text-only example');
return segment.text;
}).join('');
this.add.text(24, 24, text, {fontSize: '24px', wordWrap: {width: 720}});
}
}
new Phaser.Game({type: Phaser.AUTO, width: 800, height: 300, scene: FirstText});Expected: “Welcome to the harbour. I am Mira.” With locale = "de" or the language parameter de: “Willkommen im Hafen. Ich bin Mira.” A missing language uses source text. This sample supports text segments; it deliberately does not silently discard placeholders.
3 · From one sentence to a conversation
The fixed text ID above is for the first test. In your game choose flowRef/entryRef from story-index.json, read execution.entries[entryRef].nodeRef, then execution.nodes[nodeRef]. The current dialogue supplies text.textRef and speakerRef. Continuations depend on node kind.
Name/dialogue: Text.setText(). Answers: Text.setInteractive() and pointerdown, each carrying its option ID. End: hide dialogue objects with setVisible(false) and disable their input; keep the game scene running.
- Continue and End: follow connections, close the text box
- Choices: answer ID, order and selected continuation
- Conditions and variables: ten or two gold
- Language: the same IDs, newly resolved content
- Command: give an item or open a shop
- Call/Return: visit a substory and return
Inspect answers and the gold check in this language
Read the data for a choice
Insert this fragment where story is available after loading (for RPG Maker: const story = $gameTemp.vnleExample.story;). It prints IDs for inspection. Replace the output with your answer buttons. It covers the two Harbour answers and their following gold check, not a general interpreter.
// story is already loaded. Keep each optionId on its answer button.
const choice = story.execution.nodes['42edfff8-b8fe-46bf-ae0d-9e2347b6e726'];
for (const optionId of choice.optionOrder) {
const option = choice.options[optionId];
console.log(optionId, option.text.textRef); // Resolve text, then create your button.
}
// Inspect the actual purchase check. This particular node is Gold >= 5.
const branch = story.execution.nodes['c1c3c372-0a73-4cd0-851d-ede59d5709bb'];
const gold = 10; // Repeat with 2, using your current game value.
const next = gold >= branch.condition.right.value.value ? branch.whenTrue : branch.whenFalse;
console.log(next.nodeRef);With 10 gold, next refers to “Pay five gold”; with 2 it refers to “Not enough gold”. In the actual game, run the check only when the selected path reaches this node. Each selected answer supplies its own continuation.
4 · Map your own images
This supplementary excerpt expects a current dialogue object named node and the UI elements named in its comments. For C++ and MonoGame, speakerRef has already been read as SpeakerId or speakerId. The key is Mira’s actual character ID; the image name and location belong to your game. Insert the lines at the indicated locations.
// preload(): the key is a real VNLE character ID; the file is yours.
this.load.image('807b2957-7bab-4a28-83a4-1f3d1589bbc2', 'assets/portraits/mira.png');
// create(): keep one image for the dialogue bar.
this.portrait = this.add.image(100, 180, '807b2957-7bab-4a28-83a4-1f3d1589bbc2').setVisible(false);
// When showing a dialogue; node is your current dialogue object:
const key = node.speakerRef;
this.portrait.setVisible(Boolean(key && this.textures.exists(key)));
if (key && this.textures.exists(key)) this.portrait.setTexture(key);Resolve speaker names through content.characters[speakerRef].nameTextRef just like dialogue text. Missing mappings should hide the previous portrait or show a placeholder. Images are not selected by language.
Use image references from the complete export
5 · Ship files with the game
Keep JSON and images in the published web folder. Paths are relative to the HTML page unless a loader path is configured. Use the data in create; preload queues the requests. Check load failures.
Check your result
- English and German greetings display correctly; an unavailable language falls back to English.
- When adding flow: try both answers, gold 10/2, the return from the substory and End.
- Run the built game outside your project folder. JSON, fonts and portraits must be available there too.
Official documentation
API and setup references for this approach: