LogoPixi’VN

Characters

How to define, use, and customize characters in Pixi’VN, including storage, emotions, and custom properties.

What are characters? Characters are the actors that appear in a visual novel. In Pixi’VN, characters are created using the CharacterBaseModel class or a custom class.

Initialize

To initialize a character, create a new instance of the CharacterBaseModel class (or your custom class) and add it to the game character dictionary when the game is initialized.

It is recommended to import the instances at project startup.

RegisteredCharacters.add is required to save the characters in the game.

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: "https://example.com/emma.png",
    color: "#9e2e12",
});

RegisteredCharacters.add([liam, emma]);

Get

To get a character by its id, use the RegisteredCharacters.get function.

import { RegisteredCharacters } from "@drincs/pixi-vn";

const liam = RegisteredCharacters.get("liam");

Get all

To get all characters, use the RegisteredCharacters.values function.

import { RegisteredCharacters } from "@drincs/pixi-vn";

const characters = RegisteredCharacters.values();

Use

ink

You can use this method with the ink syntax. See more here.

You can use a game character, for example, to link it to the current dialogue. You can use the character's id or the character's instance, but it is recommended to use the instance.

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

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

Edit

ink

You can use this method with the ink syntax. See more here.

CharacterBaseModel is a stored class, which means its properties are saved in game storage. For example, if you change the character's name during the game, the new name will be saved in the game storage and linked to its id.

If the character's id is changed from one version to another, the system will not move the data linked from the previous id to the new id.

To get the properties used when instantiating the class, you can use the default properties.

import { liam } from "@/content/characters";
console.log(liam.name); // Liam
liam.name = "Liam Smith";
console.log(liam.name); // Liam Smith

Other features

On this page