Hello monkeys,
my problem is, that I can’t play sounds in my nifty gui, (I don’t hear any sounds except ingame). There are no errors, no warnings etc. I tried to use Stereo as well as mono sounds. Nothing is played.
You see, that equals with the documentation.
I would be very happy, if someone had this Problem too and could help me.
Good evening,
Domenic
EDIT:
I tried to use instead of “onClick” → “onStartHover”. That works! The Sound was played successfully. Could it be, that the onClick effect doesn’t work at Buttons, because they have already an “onClick-method” in use ?
I had this problem at one point and i’m pretty sure it had to do with the fact that you aren’t setting the on click effect on the root component that receives the mouse click which calls “startGame”. So your game transitions to a new screen and the mouse event never propagates to where you are setting playSound.
I have mine set in a button style which can effect the root panel that you are actually clicking on. For example:
No, that’s not what I meant. All controls in Nifty are a bunch of nested components. So I button has a couple different panels and a label for example. So for your use case where you are transitioning to a different screen or starting your game you need to apply it directly to the root panel that gets the click event. That root panel lives INSIDE the button control itself.
The <effect> tag containing the <onClick ... /> tag is inside the Control-tag.
As I said, without the <interact onClick="startGame()"/> it does work. But both together don’t. Could you please tell me what the rootPanel of the button exactly is and where I have to insert my
Okay, you’re right. If I click the button and the “start”-Screen isn’t changing the sound will be played. But normally I change to a “loading”-screen and it that case it doesn’t work! Is there no way to simply make them work?
That’s what I said earlier. You need to create a style and apply it to the button in order to target the root element and get the sound to play when you change screens. I have the style I use in the post above.
I get the following exception, but the game doesn’t crashs. However, it doesn’t work at all. I’m very frustrating
Warnung: missing font in renderText! could it be that you're using <text> elements without a font or style attribute? in case you've replaced <label> with <text> you're probably missing style='nifty-label' :)
EDIT (My alternative solution):
I found another solution: In my case the sound should play when I click on the button. After the click the Screen is changed immediately. So the Sound cannot be played, because the Screen is already “gone”.
But if I insert this line for example:
<onEndScreen name="fade" ... length="1" />
You see it will work!
I think it is not the cleanest solution, but better than nothing.
I fixed that a few minutes later after I have uploaded this post. But it still not works. However. Maybe I will use this in a couple of months, but until then I will use the solution I wrote above.