add onCharacterTyped signal in FlxTypeText which will dispatch when t…#468
add onCharacterTyped signal in FlxTypeText which will dispatch when t…#468ninjamuffin99 wants to merge 2 commits intoHaxeFlixel:devfrom
Conversation
…he character changes
flixel/addons/text/FlxTypeText.hx
Outdated
| */ | ||
| public var eraseCallback:Void->Void; | ||
|
|
||
| public var onCharacterTyped(default, never):FlxSignal = new FlxSignal(); |
There was a problem hiding this comment.
Thoughts on this:
public final onTextAdded = new FlxTypedSignal<String>();TBH, I didn't know (default, never) was valid code, final is more typical of things defined once at construction.
I also assume that the type rate can be fast enough that multiple chars can be typed in a single frame, not sure though. but sending the chars will allow people to use custom sounds or logic depending on the character
Lastly, destroy should clear all listeners
There was a problem hiding this comment.
ah good catch, i think the (default, never) bit is just a random habit i have, using final make sense
There was a problem hiding this comment.
updated with:
- using
finalinstead of(default, never) - destroy the signal with
FlxDestroyUtil.destroy(onCharacterTyped)in an overridden destroy function
| onComplete(); | ||
| onCharacterTyped.dispatch(); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
… when the character changes
|
It would be cool if it was a FlxTypedSignal so you can get the exact character typed easily |
|
I don't know if it matters but this exists |
…he character changes
When FlxTypeText outputs a new character, we dispatch our newly created
onCharacterTypedFlxSignal.This could also be useful in cleaning up some of that update code that runs the sounds for each character.