LogoPixi’VN
叙事使用 JS/TS 进行叙事

对话

如何在 Pixi’VN 中使用、自定义和管理对话对象,包括"グルー"(glue)和 UI 集成。

UI 界面

您可以在 界面示例 部分找到叙事对话 UI 界面的示例。

什么是对话? 一种书面作品,其中两个或多个角色被描述为正在交谈。

在 Pixi’VN 中,dialogue 是一个包含当前在说以及说了什么的信息的对象。 其功能可以更广泛,因为它也可以用于其他目的,例如独白、自言自语,或向玩家显示消息。 因此,将其视为可以与角色关联的文本更为恰当。

设置

要设置当前对话,可以使用 narration.dialogue

content/labels/start.label.ts
import { narration, newLabel } from "@drincs/pixi-vn";
import { eggHead } from "@/content/characters";

export const startLabel = newLabel("start", [
    // A simple dialogue with only text, without a character
    () => (narration.dialogue = "Hello, world!"), 
    // A dialogue with a character
    () => {
        narration.dialogue = { 
            character: eggHead, 
            text: "My name is ${eggHead.name}!", 
        }; 
    },
    // A dialogue with a character, but the character is not defined in the characters list
    () => {
        narration.dialogue = { 
            character: "Narrator", 
            text: "This is a narration without a character.", 
        }; 
    },
]);

获取

要获取当前对话,使用 narration.dialogue。 返回值是一个 DialogueInterface

const currentDialogue: DialogueInterface = narration.dialogue;

删除

要清除当前对话,将 narration.dialogue 设置为 undefined

narration.dialogue = undefined;

自定义类

您可以通过向 DialogueInterface 添加额外属性来自定义对话接口。 例如,可以添加 color 属性来更改文本颜色。

为此,请在您的 .d.ts 文件中"覆盖" DialogueInterface 接口:

declare module "@drincs/pixi-vn" {
    interface DialogueInterface {
        color?: string;
    }
}

其他功能

On this page