应用程序中的 Java 游戏声音(例如,而不是小程序)
我有两个问题 - (1) 如何播放小声音片段,例如飞碟飞行、子弹射击、物体被子弹击中等。声音非常短,但实时。我喜欢旧的街机声音,所以它们不需要很大的 .wav。我想用尽可能少的代码来运行它们。这引出了我的第二个问题...... (2) 有谁知道在哪里可以找到这些声音片段。
请注意,我在这里看到了一些答案,但它们似乎不完整。如果您有一个直接的通用代码,那就太好了!我对声音知之甚少,因为我通常不会在游戏写作中走得这么远。
感谢您提供的所有信息 - 我非常感激!
I have two questions - (1) How to play small sound clips, e.g. saucer flying, bullets shooting, things getting hit with bullets, etc. Very short, but real-time, sounds. I like the old arcade sounds, so they need not be largess .wav's. I want to run these in as little code as possible. Which leads to my second question...
(2) Does anyone know where to find these sound clips.
A little note, I've seen some of the answers here, and they seem incomplete. If you have a straight, generic code, that's great! I know very little about sounds as I don't normally get this far in my game writing.
Thanks for any and all information - I do appreciate it!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
使用javax.sound,可以实现简单的声音效果。
编辑:使用线程(或不使用)
Using javax.sound, it's possible to have simple sound effect.
EDIT: Using a Thread (or not)
我不知道 API 部分,但对于声音,请尝试 www.sounddogs.com
I don't know about the API part, but for the sounds try www.sounddogs.com
Clip 接口是在应用程序中播放小声音的最简单方法。 这里是一个示例。如果您想播放 wav 以外的任何内容,请使用 JavaZOOM 中的 MP3SPI 或 VorbisSPI。
Clip interface is the easiest way to play small sounds in your app. Here is an example. If you want to play anything other than wav, use MP3SPI or VorbisSPI from JavaZOOM.
好吧,伙计们——这就是我在等待时想到的。我以为我已经将 Stack Overflow 设置设置为在我的问题得到解答时向我发送电子邮件,所以我以为我还没有收到任何答复。于是,我就一个人继续前行。
这是我发现有效的方法。
(1) 使用以下方法创建实例:
(2) 并创建文件 PlaySounds.java (或任何您喜欢的文件)
导入 java.io.;
导入javax.media。;
公开课 PlaySounds
{
私人玩家玩家;
私人文件文件;
} // 文件结尾 PlaySounds.java
(3) 要使用,请将它们插入到您想要声音的位置:
这是我发现的最短/最甜蜜的。非常易于使用,可以播放 .au 和 .wav 文件。
我非常感谢你们所有的帮助。
Okay guys - here's what i came up with while I was waiting. I thought I had set the Stack Overflow settings to email me when my question was answered, so I thought I received no answers yet. Thus, I continued on by myself.
Here's what I found that worked.
(1) Create the instance by using this:
(2) And create the file PlaySounds.java (or whatever you like)
import java.io.;
import javax.media.;
public class PlaySounds
{
private Player player;
private File file;
} // End of file PlaySounds.java
(3) To use, insert these where you want the sounds:
This was the shortest / sweetest I found. Very easy to use, and plays both .au AND .wav files.
I do appreciate all your help guys.