跳转到内容
Pixi’VN

角色

如何在 Pixi’VN 中定义、使用和自定义角色,包括存储、情感和自定义属性。

什么是 characters? 角色(characters)是出现在视觉小说中的演员。在 Pixi’VN 中,角色使用 CharacterBaseModel 类或自定义类创建。

初始化

要初始化角色,创建 CharacterBaseModel 类(或您的自定义类)的新实例,并在游戏初始化时将其添加到游戏角色字典中。

RegisteredCharacters.add 是必须的,用于将角色保存到游戏中。

content/characters.ts
import { CharacterBaseModel, RegisteredCharacters } from "@drincs/pixi-vn";

export const liam = new CharacterBaseModel("liam", {
    name: "Liam",
    surname: "Smith",
    age: 25,
    icon: "https://example.com/liam.png",
    color: "#9e2e12",
});

export const emma = new CharacterBaseModel("emma", {
    name: "Emma",
    surname: "Johnson",
    age: 23,
    icon: "emma", // If is defined in the assets, you can use the name of the asset instead of the url.
    color: "#9e2e12",
});

RegisteredCharacters.add([liam, emma]);

使用方法

ink

你可以在 ink 语法中使用此方法。查看更多 此处。

您可以使用游戏角色,例如,将其链接到当前对话。您可以使用角色的 id 或角色实例,但建议使用实例。

import { liam } from "@/content/characters";

narration.dialogue = { character: liam, text: "Hello" };
// or
narration.dialogue = { character: "liam_id", text: "Hello" };

编辑

ink

你可以在 ink 语法中使用此方法。查看更多 此处。

import { liam } from "@/content/characters";

console.log(liam.name); // Liam
liam.name = "Liam Smith";
console.log(liam.name); // Liam Smith

其他功能

本页内容