-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pausing issue in v1.1.1 #37
Comments
We are currently using pos3d extensively in our newest game and haven't run into any issues. Are you still seeing this in 1.1.4, and if so, can you post some sample code? |
Hi James, |
Hi again, I got it to work correctly with my hack above, but I don't really want to have to do this. I will post back with the source code. Must go to bed. :-) |
Here's some sample code. I only included the relevant parts for playing a sound that repeats quickly: //use jQuery to listen for a Key pressed down
$(document).keydown(function(e) {
//this keys[] array will hold all keys that are being pressed
keys[e.which] = true; //[e.which] returns the key code and
//thus that element of the keys[] array will be 'true'
});
//when user releases a key upwards, it is no longer needed so delete it
$(document).keyup(function(e) {
delete keys[e.which];
});
//for a real game, requestAnimationFrame() should be used, but for this demo,
//the setInterval() function will do. Every 100 milliseconds (1000 / 100 =
// about 10 times a second), it fires the callback function scanKeyboard()
setInterval(scanKeyboard, 100); //(could change the '100' to '17' for around 60 times a second)
//this function is called every 100 milliseconds in the setInterval() function above
function scanKeyboard() {
//iterate through the keys[] array
for (var i in keys) {
if (!keys.hasOwnProperty(i))
continue; //didn't have a property, so continue on to the next 'i' index.
// otherwise, test if the SPACE bar is pressed (key code is 32)
if (i == 32) {
posValueX = $("#sliderX").slider("value"); //set posValueX to sliderX value
posValueY = $("#sliderY").slider("value"); //set posValueY to sliderY value
posValueZ = $("#sliderZ").slider("value") * -1.0; //set posValueZ to -(sliderZ) value
powerupSound.pos3d(posValueX, posValueY, posValueZ);
powerupSound.play();
}
}
} I suspect that this whole problem of echoing sounds has to do with how sounds are supposed to be rapidly repeated in Howler. Lets say I code something like this: for(i=0; i<shotsFired; i++){ Is this the correct way to use fast repeating sounds in Howler? Or should I say for i<shotsFired machineGunSound[i] = new Howl(...) , and just create a separate Howler sound object for each bullet? Thanks for taking a look at this. |
What happens if you change this: powerupSound.pos3d(posValueX, posValueY, posValueZ);
powerupSound.play(); to this: powerupSound.play(function(soundId){
powerupSound.pos3d(posValueX, posValueY, posValueZ, soundId);
}); |
Hi James, thanks for the suggestion. I will try it tonight - I have to work right now but I will be at my computer later. I will post soon with the results. |
It still doesn't work for me. It doesn't play any sound at all. Do I have to replace the word (soundId) with something of my own or can I use what you provided as-is? Does soundId somehow have to change each iteration? Thanks for your help. |
Can you post the code that defines |
Yes, here it is: var powerupSound = new Howl({
urls : ['powerup.mp3']
}); And here is my updated pos3d function call, using your earlier suggestion: setInterval(scanKeyboard, 100);
//this function is called every 100 milliseconds in the setInterval() function above
function scanKeyboard() {
//iterate through the keys[] array
for (var i in keys) {
if (!keys.hasOwnProperty(i))
continue;//didn't have a property, so continue on to the next 'i' index.
// otherwise, test if the SPACE bar is pressed (key code is 32)
if (i == 32) {
posValueX = $("#sliderX").slider("value"); //set posValueX to sliderX value
posValueY = $("#sliderY").slider("value"); //set posValueY to sliderY value
posValueZ = $("#sliderZ").slider("value") * -1.0; //set posValueZ to -(sliderZ) value
powerupSound.play(function(soundId){
powerupSound.pos3d(posValueX, posValueY, posValueZ, soundId);
});
}
}
} I would eventually like this to trigger a machine-gun effect so when the player holds down SPACE or 'fire' button, multiple shot sounds will play rapid-fire over one another without cutting the earlier ones off. So I guess what I'm looking for is a way to have multiples of the same sound with a unique 3D position and start/stop time for each (which I'm guessing requires a unique identifier for each?). Thanks for any help you can give me. |
Sorry, that is my mistake, I typed up my example wrong. Try this: powerupSound.play(null, function(soundId){
powerupSound.pos3d(posValueX, posValueY, posValueZ, soundId);
}); |
Yes! It works! That did the trick like magic. I guess what my demo needed was a unique id for each sound that was triggered rapid-fire by holding down the SPACE key. If you like, I can now post the source code for this little demo as it works the way I intended. |
Please post, I'm sure others would find it useful. Thanks! |
Hi James,
I opened this issue in relation to the recently closed issue that I had started. I feel this is still a relevant issue. There is a pausing problem while trying to use the new .pos3d() method to pan a sound, then playing a sound once, twice, or repeating the sound rapid-fire (like a machine-gun effect in a game).
I found the problem magically goes away when I make a simple boolean change to your howler.js code:
This came from the play: function . I'm sorry this is kind of a hack and I don't really understand the inner workings of howler well enough to know why this works, but it does.
Can you safely work it in to the next version so we can use the .pos3d() method with the intended results?
Thanks James. Howler 1.1.1 rocks!
The text was updated successfully, but these errors were encountered: