sound effects on different events in Phys2d

Hi,

I’m new to game programming. Currently I’m working on Phys2d to make some physics related simulations. i.e. two Balls colliding, object moving on surface with certain friction etc etc.

Now I want to add some sound effects in it. it plays collision sound when two balls collide with eachother.
I don’t know how to do that. Could anyone pls guide me to accomplish this.

Thanks in advance.

Are you using LWJGL? Or Java2D? Have you actually tried searching the forums for a sound library? There are plenty of threads here dealing with exactly what you want.

I’m using Java2d for rendering where as for physics library I’m using Phys2d.

Since you are just getting into it for the first time, maybe using a Clip makes the most sense.
http://docs.oracle.com/javase/tutorial/sound/playing.html

If you are willing to use a library, TinySound is probably the best choice for starters.

I did a search on “java sound clip tutorial”
This one looks reasonable (uses the native javax.sound.sampled library):
http://www3.ntu.edu.sg/home/ehchua/programming/java/J8c_PlayingSound.html