Skip to content
This repository was archived by the owner on Dec 30, 2023. It is now read-only.

Dialogue Script

skellypupper edited this page May 29, 2023 · 17 revisions
Empty Script

Example dialogue scripts can be found here.

function create() {}
function update(elapsed:Float) {}
function preLine(portrait:String, ?textLine:String) {}
function finish() {
    // code here
    dia.finishCallback();
    dia.kill();
}

How to use

Make a dialogue script at dialogue/<boxname>/init.hxs, you can also place your box assets in the <boxname> folder.

You can use your dialogue box in a song script by calling game.openDialogueBox.

ex: game.openDialogueBox("<boxname>", [":bf:swag", ":dad:money"], game.startCountdown)

Variables

  • dia: The current dialogue class, used to edit the dialogue box.
  • dia.portraits: A Map that holds portraits for all dialogue characters.
  • dia.speakTxt: The FlxTypedText instance that reads out the dialogue.
  • dia.groupTxt: A FlxTypedGroup containing the speakTxt. Really only added to be used for the drop shadow text in week 6.
  • dia.box: A null FlxSprite that is meant to be defined in the create() callback. If it's null after create is complete, the dialogue instance will close itself. If you really don't need a box sprite, you can set it to the bare minimum as shown below:
import flixel.FlxSprite;

function create() {
    dia.box = new FlxSprite();
}
  • Paths: A custom paths instance that only reads for files inside the <boxname> directory.
  • _Paths: The global paths instance.

Callbacks

Required

  • create(): Where you actually initialize everything.

Optional

  • createPost(): Called after the class is created.
  • preLine(portrait:String, ?textLine:String): Called before the next line plays.
  • update(elapsed:Float): Called every frame.
  • finish(): Called when the dialogue complete or the player skips it early. If you use this callback you'll need to call the ending code: dia.finishCallback();dia.kill();.

Portraits

You can set portraits like this: dia.portraits["namehere"] = new FlxSprite(); And set the sprite properties.

Portrait Animations

There are a few animations you can add to your portrait sprites to make them move during dialogue.

  • pre: Before the next dialogue line starts, this animation will play.
  • enter: Whenever your portrait becomes visible, it will play once when the text starts.
  • talk: While the dialogue is still being typed out, this animation will play.