Code Monkey home page Code Monkey logo

Comments (12)

goldfire avatar goldfire commented on May 18, 2024

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?

from howler.js.

erichlof avatar erichlof commented on May 18, 2024

Hi James,
I have yet to download 1.1.4 and I am about to go to work. So, later tonight I will test it and post code if there is still a problem. I've been recently suspecting that it has less to do with pos3d and more to do with fast repeated sounds. I might have to learn from you the correct way to play stuff like machine gun fire (lots of the same sounds in a row without cutting the previous one off). I will check back in soon. Thanks!

from howler.js.

erichlof avatar erichlof commented on May 18, 2024

Hi again,
Yes unfortunately it is still echoing/delaying repeated sounds in v1.1.4. If I play a sound to the left (comes to my left ear), then move slider to the right and play the sound again, it still plays out of the old left ear position, but fainter. And now I end up with two sounds, one coming out of the left position (incorrectly) and a louder one coming out of the right position (correct). Howler is somehow retaining that older position even though I have long since moved away from there. It will continue to play it there for about 4 times, so I end up eventually with a history trail of sounds - heh heh, sort of like quantum parallel "many universes" theory! Cool, but not what I'm expecting.

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. :-)

from howler.js.

erichlof avatar erichlof commented on May 18, 2024

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++){
machineGunSound.play();
}

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.

from howler.js.

goldfire avatar goldfire commented on May 18, 2024

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);
});

from howler.js.

erichlof avatar erichlof commented on May 18, 2024

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.

from howler.js.

erichlof avatar erichlof commented on May 18, 2024

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.

from howler.js.

goldfire avatar goldfire commented on May 18, 2024

Can you post the code that defines powerupSound?

from howler.js.

erichlof avatar erichlof commented on May 18, 2024

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.

from howler.js.

goldfire avatar goldfire commented on May 18, 2024

Sorry, that is my mistake, I typed up my example wrong. Try this:

powerupSound.play(null, function(soundId){
    powerupSound.pos3d(posValueX, posValueY, posValueZ, soundId);
});

from howler.js.

erichlof avatar erichlof commented on May 18, 2024

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.
Thanks so much for your patience and help James!
-Erich

from howler.js.

goldfire avatar goldfire commented on May 18, 2024

Please post, I'm sure others would find it useful. Thanks!

from howler.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.