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

对话

如何在Pixi'VN 中使用、定制及管理对话对象,包括粘合功能和 UI 集成。

UI screen

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

什么是对话(dialogue)? 它是一种书面创作形式,其中有两个或多个角色进行交谈。

在Pixi'VN中,对话(dialogue)是一个对象,包含了当前_谁_在说话以及_说了什么_之类的信息。 它的功能可以更广泛,因为它也可以用于其他目的,例如独白、自言自语,或向玩家显示一条消息。 因此,将其视为可以链接到角色的文本更为恰当。

设置

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

labels/startLabel.ts
import { narration, newLabel } from "@drincs/pixi-vn"
import { eggHead } from "../values/characters"

// 什么是标签?请看https://pixi-vn.web.app/start/labels.html
export const startLabel = newLabel("start_label",
    [
        () => {
            // 在这个例子中,并不存在一个名为“Alice”的角色
            // 所以,如果你获取现在对话,它的角色会是一个名为“Alice”的假角色
            narration.dialogue = { 
                character: "Alice", 
                text: "Hello, world!"
            } 
        },
        () => {
            // 在这个例子中,的确存在一个名为“egg-head”的角色'
            //  所以,如果你获取现在对话,它的角色将会是id为“egg-head”的那个角色
            narration.dialogue = { 
                character: 'egg-head', 
                text: "你好,世界!"
            } 
            // 或者更好些
            narration.dialogue = { 
                character: eggHead, 
                text: "你好,世界!"
            } 
        },
        // 如果你不想设置任何角色,你可以直接传一条字符串
        () => narration.dialogue = "Hello, world!", 
    ],
)

获取

要获取当前对话框,使用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