Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions flixel/addons/text/FlxTypeText.hx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import flixel.math.FlxMath;
import flixel.system.FlxAssets;
import flixel.text.FlxText;
import flixel.sound.FlxSound;
import flixel.util.FlxSignal;
import flixel.util.FlxDestroyUtil;
import flixel.math.FlxRandom;
import openfl.media.Sound;

Expand Down Expand Up @@ -110,6 +112,11 @@ class FlxTypeText extends FlxText
*/
public var eraseCallback:Void->Void;

/**
* Dispatches each time a character is typed.
*/
public final onCharacterTyped:FlxSignal = new FlxSignal();

/**
* The text that will ultimately be displayed.
*/
Expand Down Expand Up @@ -439,6 +446,8 @@ class FlxTypeText extends FlxText
_length += Std.int(_timer / delay);
if (_length > _finalText.length)
_length = _finalText.length;

onCharacterTyped.dispatch();
}

if (_erasing && _timer >= eraseDelay)
Expand Down Expand Up @@ -516,6 +525,7 @@ class FlxTypeText extends FlxText
if (_length >= _finalText.length && _typing && !_waiting && !_erasing)
{
onComplete();
onCharacterTyped.dispatch();
Comment on lines 518 to +528
Copy link
Member

@Geokureli Geokureli Nov 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems odd to dispatch this after onComplete. I also wonder if rather than calling it in two places can we just dispatch it once, immediately after the text is changed

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that doesn't account for the cursorCharacter, so when the cursor blinks, it will incorrectly dispatch the signal. This signal is meant a bit specifically for when a character is actually added/changed in the FlxTypeText. I think right now FlxTypeText can be cleaned up a bit in general, where these 2 dispatches can become 1 more simply along with other little tidyings

}

// If we're done erasing, call the onErased() function
Expand Down Expand Up @@ -554,4 +564,10 @@ class FlxTypeText extends FlxText
_sound.loadEmbedded(new TypeSound());
#end
}

override public function destroy():Void
{
FlxDestroyUtil.destroy(onCharacterTyped);
super.destroy();
}
}