I have been experimenting with PulpCore, trying to create my own tower defence game (not-playable yet), and I am enjoying it very much I ran into a problem that I can't quite figure out. I extended PulpCore with the JOrbis thing to allow OGG files to be played. Works fine. However, pulpCore seems to have a problem with looping the sound WHILE animating the volume level. I tried this with wav file too, to make sure it isn't jOrbis that breaks it. The code is like this:
Sound bgMusic = Sound.load("music/music.ogg");
Playback musicPlayback;
...
musicVolume = new Fixed(0.75);
musicPlayback = bgMusic.loop(musicVolume);
//TODO figure out why it's NOT looping when volume is animated
// musicVolume.animate(0, musicVolume.get(), FADE_IN_TIME);
This code, for as long as the last line is commented out, plays the music.ogg again and again in an endless loop (which I can stop by calling stop on the Playback object returned from loop(). However, I would like the music to fade in smoothly, so following the advice of the PulpCore API docs, I added the last line which will create the fade-in but the music will only play once and then stop. I wonder why is that? Here is a bit of the documentation:
Playback pulpcore.sound.Sound.loop(Fixed level)
Loops this sound clip with the specified volume level (0.0 to 1.0). The level may have a property animation attached.
Parameters: level
Returns: a Playback object for this unique sound playback (one Sound can have many simultaneous Playback objects) or null if 开发者_开发问答the sound could not be played.
So what could be the problem? I repeat, with the last line, the sound fades in but doesn't loop, without it it loops but starts with the specified 0.75 volume level. Why can't I animate the volume of the looped music playback? What am I doing wrong? Anyone has any experience with pulpCore and has come across this problem? Anyone could please download PulpCore and try to loop music which fades-in (out)?
note: I need to keep a reference to the Playback object returned so I can kill music later.
If the animate
method only sets the option, it can work unpredictably - try switching this line with the loop itself, so the animation applies first.
Can you animate the volume on an unlooped playback, and then, at the end of that playback, start the loop at the fixed level?
Finally I managed to get an explanation and a simple work-around for this issue from the pulp core author. So here it is:
It is a PulpCore bug. When the output volume is zero, the sound player stops looping the sound.
To work around it, animate from a value that is not zero, like this:
musicVolume.animate(0.0001, 1, FADE_IN_TIME);
Link to this on pulpcore Google groups
精彩评论