flixel-addons icon indicating copy to clipboard operation
flixel-addons copied to clipboard

FlxTypeText doesn't play sounds frequently enough for HTML5 targets

Open Poobslag opened this issue 2 years ago • 1 comments

In HTML5 projects, FlxTypeText will play typing sounds very sparsely -- only about half as frequently as other targets such as Flash.

This appears to be caused by a bug in FlxSound, which continues continue playing a sound past the sound's length. Even if a sound is only 25 ms, it will continue playing and the FlxSound.time value will progress to 35, 45, and 55 ms before finally stopping.

This applies to playing .wav files when the finishSounds flag is set, I have not tested the issue with .mp3 or .ogg files.

Poobslag avatar May 23 '23 00:05 Poobslag

I have workaround this bug in my game by amending FlxTypeText to include the following code:

-					FlxG.random.getObject(sounds).play(!finishSounds);
+					var sound:FlxSound = FlxG.random.getObject(sounds);
+					#if flash
+					sound.play(!finishSounds);
+					#else
+					sound.play(!finishSounds || (sound.time > sound.length));
+					#end

Poobslag avatar May 23 '23 00:05 Poobslag