Skip to content

Instantly share code, notes, and snippets.

@dogboydog
Created July 18, 2025 01:35
Show Gist options
  • Save dogboydog/dc2cdc683cccc1ea482b212126199252 to your computer and use it in GitHub Desktop.
Save dogboydog/dc2cdc683cccc1ea482b212126199252 to your computer and use it in GitHub Desktop.
YarnSpinner for Godot - Play sounds when characters are revealed from the typewriter effect
using System;
using System.Threading;
using Godot;
using Godot.Collections;
using Yarn.Markup;
using YarnSpinnerGodot;
namespace MyGame;
public partial class DialogueTypewriterSounds : ActionMarkupHandler {
[Export] public Array<AudioStream> typewriterSounds;
private DateTime _lastTypeWriter = DateTime.Now;
private const float TYPEWRITER_COOLDOWN = 0.05f;
public override void OnLineDisplayComplete() { }
public override void OnLineWillDismiss() { }
public override void
OnPrepareForLine(MarkupParseResult line, RichTextLabel text) { }
public override void
OnLineDisplayBegin(MarkupParseResult line, RichTextLabel text) { }
public override YarnTask OnCharacterWillAppear(int currentCharacterIndex,
MarkupParseResult line,
CancellationToken cancellationToken) {
var elapsed = DateTime.Now - _lastTypeWriter;
if (elapsed <= TimeSpan.FromSeconds(TYPEWRITER_COOLDOWN)) {
return YarnTask.CompletedTask;
}
// todo : <play a sound from typeWriterSounds here >
_lastTypeWriter = DateTime.Now;
return YarnTask.CompletedTask;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment