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.
RegisteredCharacters.add is required to save the characters in the game.
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]);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.
import { liam } from "@/content/characters";
console.log(liam.name); // Liam
liam.name = "Liam Smith";
console.log(liam.name); // Liam Smith