2017-06-05 12:29:21

Hello,
I am really confused with the sound pool thing in BGT. Could someone explain why is better to use it instead of using the ordinary sound play metod? Which are the advantages? And also, could someone make a small code example and comment it? I'm really confused about it, and a better explaination would be really, really appreciated.
Thank you in advance

2017-06-05 15:01:12

Well, it is better used because its just easier than actually using sound objects and having to update them all. Its mainly used for big projects, I mostly use the sound object if I want to play a few sounds, etc etc etc. Here's an example of how to use it.

//include the script
#include"sound_pool.bgt"
//define the class
sound_pool p;
void main()
{
//make a few variables
int listener_x=5;
int listener_y=5;
int x=2;
int y=6;
//now we play a sound.
p.play_2d("sound.ogg",listener_x, listener_y, x, y, false);
}

Ivan M. Soto.
Feel free to check out my work and services.
http://ims-productions.com

2017-06-05 16:34:28

Thank you very much for your explaination.
I still have two more questions.
1. Do I have to write play_sound_2d over and over again when using this metod? For example
if(key pressed(KEY_UP)
{
x++
play_sound_2d etc etc etc)
}
Or I simply put the sound like you did and that's all?
2. I've plaied with sound_positioning for some time, and everything's going quite well.
I have one issue though. I have no idea how to make a sound to be heared in the center for more time while walking.
Let's say I placed a river somewhere on the map. When using sound_positioning, the river can be heared just on the square where is placed, then if you move, the sound starts decreasing.
What I want to do, is to make that river hear in the center let's say for 10, 20 squares.
What method would you advise me to use?

2017-06-05 21:06:15

The sound_pool has a method for the river example, but it takes several arguments, and it can be hard to remember all of them and what order they're in.
pool.play_extended_2d("river.wav", listener_x, listener_y, sound_x, sound_y, left_range, right_range, backward_range, forward_range, looping, offset, start_pan, start_volume, start_pitch);
In this case, I'd make looping = true, and ofset and start_ values 0.0, except for start_pitch, because a pitch of 0 is almost inaudible. If you don't want any special pitch, just use 100.
I find play_extended methods to be somewhat cumbersome, so I write a function to save time. However, this works because I usually keep track of the camera separately, and use geometric objects to keep all the position and range values manageable.

Basically, the sound_pool is a fire-and-forget method of playing sounds. It allows you to easily update the entire soundscape when the player moves, but optionally keep variables for the sound slots, if you need to move them individually. You can also set all of your step and behind variables once (or just use the defaults), and never type them again. You can easily pause_all, resume_all, and destroy_all.
You might call it a soundscape manager.

看過來!
"If you want utopia but reality gives you Lovecraft, you don't give up, you carve your utopia out of the corpses of dead gods."
MaxAngor wrote:
    George... Don't do that.

2017-06-15 18:20:03

If you don't want to type the whole function Name every time, write your own function with a shorter Name that does nothing but call the pool-function.

We are pleased, that you made it through the final challenge, where we pretended we were going to murder you. We are throwing a party in honor of your tremendous success. Place the device on the ground, then lay on your stomach with your arms at your sides. A party associate will arrive shortly to collect you for your party. Assume the party submission position or you will miss the party.