Sound Trouble with Tutorial
Hi! I'm brand new to HaxeFlixel and I've been working through the tutorial and I've made to this stage:
I did the first step to load a music file, and I had some trouble because I've been building for windows instead of flash, but after converting the mp3 to ogg, the music has been working fine. On step 2, where you add a sound "select.wav" to the buttons in MenuState.hx, the sound doesn't play when the buttons are pressed. However, the same code and sound in OptionsState.hx works just fine and other sounds play in CombatHUD.hx as well.
A quick search turned up this: https://github.com/openfl/openfl/issues/998 , so I made a new state, InitState.hx to try initializing the sound before getting to MenuState.hx. I loaded a FlxSound in InitState.hx and it plays, but the button sounds in MenuState.hx still weren't playing. Then I tried loading a FlxSound in MenuState.hx and playing it in the functions that are called when the buttons are pressed and that didn't work either.
Then I wanted to see if the problem was just with the Windows build target, so I tried building for html5, and no sounds play at all except the music. Has anyone seen something like this before?
Edit: Disabling the music didn't change anything for either build target.
I worked my way through that tutorial as well and I have no button sounds on the MenuState in any target I've built for: Neko, Flash, Android and HTML5.
I feel better knowing that it's not just me then. I hope I can find out how to fix this and avoid it in the future.
I figured out the problem.
If you look at the callback functions for the buttons in the OptionsState you'll notice they all use a fade transition to get back to the MenuState.
The callbacks in the MenuState don't so the sounds don't get a chance to play before the state is destroyed in the switch.
If you simply add fade transitions to the callbacks in the MenuState the problem is solved.
Basically, don't destroy the state you're in before the sounds have had a chance to play.
@cg-tv Yep, that was it all right. Thanks for looking into this, it would have taken me longer than I want to admit to figure this out on my own.