PulpCore 音乐播放 - 循环声音和动画音量
我一直在尝试使用 PulpCore,尝试创建我自己的塔防游戏(还不能玩),我非常喜欢它,但我遇到了一个我不太明白的问题。我使用 JOrbis 扩展了 PulpCore,以允许播放 OGG 文件。工作正常。然而,pulpCore 似乎在设置音量动画时循环声音有问题。我也用 wav 文件尝试过,以确保不是 jOrbis 破坏了它。代码是这样的:
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);
只要最后一行被注释掉,这段代码就会在无限循环中一次又一次地播放 music.ogg(我可以通过在从 Loop() 返回的 Playback 对象上调用 stop 来停止循环。但是,我希望音乐能够顺利淡入,因此按照 PulpCore API 文档的建议,我添加了最后一行来创建淡入,但音乐只会播放一次然后停止,我想知道为什么会这样。 ?这是一些文档:
回放 Pullcore.sound.Sound.loop(固定级别)
循环播放此声音片段 指定的音量级别(0.0 至 1.0)。 该级别可能有一个属性 附动画。
参数:级别
返回:一个 Playback 对象 独特的声音播放(一个声音可以 有多个同时播放 对象)或 null 如果声音可以 不能播放。
那么可能是什么问题呢?我重复一遍,最后一行声音会淡入但不会循环,没有它它会循环但以指定的 0.75 音量级别开始。 为什么我无法设置循环音乐播放的音量动画?我做错了什么?有人有使用pulpCore的经验并遇到过这个问题吗?任何人都可以下载 PulpCore 并尝试循环淡入(淡出)的音乐吗?
注意:我需要保留对返回的 Playback 对象的引用,以便稍后可以终止音乐。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果
animate
方法仅设置该选项,则它可能会出现不可预测的情况 - 尝试使用循环本身切换此行,以便首先应用动画。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?
最后,我设法从纸浆核心作者那里得到了这个问题的解释和简单的解决方法。所以这里是:
指向pulpcore Google 网上论坛的链接
Finally I managed to get an explanation and a simple work-around for this issue from the pulp core author. So here it is:
Link to this on pulpcore Google groups