Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (475)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (530)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Slick2D, play sound at location  (Read 2261 times)
0 Members and 1 Guest are viewing this topic.
Offline P0jahn

Senior Member


Projects: 3



« Posted 2013-03-14 19:07:48 »

So, I need help with an algorithm for my 2D Game.
 
Say entity AA is emitting a sound. The strength of the emitting sound is determined by the distance between AA and BB(this could be the main character).
The further away they are, the weaker the sound is. The max distance(pass this distance and the sound volume is 0) is of course customizable.
The volume setting can be from 0.0 to 1.0.
 
Where and when to do these checks is not a problem. I know my engine and I can resolve that. How to check it is the problem.

There is a method in Slick2Ds Sound class called playAt(x, y, z) but it isn't what I expected.

Maybe there already is a way to implement this with Slick2D?
Offline StonePickaxes

JGO Coder


Medals: 4
Projects: 2


Nathan Kramber


« Reply #1 - Posted 2013-03-14 19:39:39 »

I would recommend Pauls sound library for 3D sound, found here.

Check out my website!
Offline P0jahn

Senior Member


Projects: 3



« Reply #2 - Posted 2013-03-14 20:39:02 »

Sound System jPCT supports binding Listener to Camera, thats what I am looking for, right?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Troncoso

JGO Coder


Medals: 20



« Reply #3 - Posted 2013-04-05 15:06:33 »

So, what is the issue? Unless I'm mistaken, you want the volume of audio to be proportional to the distance from the audio source.
Couldn't you just use the distance formula?



As for using the distance to change the volume, just choose a maximum distance, say 100. Any further than that and the volume is 0. So, you divide the distance by 100, and that gives you a percentage which you can use as the volume.

So, if the distance is 50, then the math would give you .5, which would be what you need. Is that right?
Offline sproingie

JGO Kernel


Medals: 201



« Reply #4 - Posted 2013-04-05 17:33:38 »

Usually you can get away with taking the sum of the squares and not the square root, and it saves you a lot of computation.  In this case, it's not just an optimization to keep the distance squared, it's actually essential, because loudness falls off exponentially with distance, not linearly. 
Offline Cero
« Reply #5 - Posted 2013-04-05 18:28:15 »

but it isn't what I expected.

That not really descriptive.

playAt(x, y, z)  does EXACTLY what you want.
make sure your sound files are MONO or it simply wont work

Offline P0jahn

Senior Member


Projects: 3



« Reply #6 - Posted 2013-04-07 19:49:31 »

but it isn't what I expected.

That not really descriptive.

playAt(x, y, z)  does EXACTLY what you want.
make sure your sound files are MONO or it simply wont work
Care to explain how the method works? What the parameters mean? The method is very poorly documented.
Offline Cero
« Reply #7 - Posted 2013-04-11 23:02:25 »

but it isn't what I expected.

That not really descriptive.

playAt(x, y, z)  does EXACTLY what you want.
make sure your sound files are MONO or it simply wont work
Care to explain how the method works? What the parameters mean? The method is very poorly documented.

its been a while since I have used Slick.

z was always a certain value, probably 1f and then just use x and y for positioning.
0f x should be left, 1f x should be right and so on

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Riven (5 views)
2014-07-23 20:17:25

ctomni231 (39 views)
2014-07-18 06:55:21

Zero Volt (36 views)
2014-07-17 23:47:54

danieldean (29 views)
2014-07-17 23:41:23

MustardPeter (32 views)
2014-07-16 23:30:00

Cero (47 views)
2014-07-16 00:42:17

Riven (48 views)
2014-07-14 18:02:53

OpenGLShaders (38 views)
2014-07-14 16:23:47

Riven (37 views)
2014-07-14 11:51:35

quew8 (33 views)
2014-07-13 13:57:52
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!