Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by jessemillar

It was mentioned two years ago that a 'loop' property would be added to ig.Sound. Has this happened and the docs just don't reflect it?

http://impactjs.com/forums/help/footstep-sound-effects

1 decade ago by dominic

Totally forgot about this, sorry.

The recent version in the git repo on your download page now has the .loop property. Please let me know if you find any problems with this.

var plasmaSound = new ig.Sound( 'media/plasma.*' );
plasmaSound.loop = true;
plasmaSound.play();

1 decade ago by Manic

One problem is that you can&039;t change volume or anything while it's looping. In order to add volume control, I allow players to change #ig.soundManager.volume and ig.music.volume.

However, with looping sounds, changing ig.soundManager.volume does nothing to the already-playing sound effect. The only way to mute it is to call the sound's stop method.

I&039;m also having level change problems with looped sound effects. I usually call #ig.music.stop() on level changes, but with looped sound effects this is tougher. If I'm switching levels with a call by anything but the entity that "owns" the sound effect, it can be tough to try to track down and stop the looped sound effect.

All this to say: I&039;d love it if sounds would check in to see if the #soundManager volume changed. Furthermore, I&039;d like it if child sounds of entities had their #.stop() method called when the entity is being removed.

By "child sound," I mean that if the code was like so:
EntitySampleEntity = ig.Entity.extend({
	sampleSound: new ig.Sound('media/sample.*')
});

sampleSound would be a "child sound" of EntitySampleEntity.

I realize that in order to implement either of these would probably be difficult and not worth it. The only way I could really see the second one working is if sounds registered themselves with ig.soundManager and you could then find them through a lookup. Anyway, that's my two cents if you want it.

I could also be missing something obvious that I should be doing, and if I am, please tell me!

TL;DR: Looped sounds are difficult to manage, and having a way to look up/manipulate them more easily (such as them checking soundManager for volume instead of having to manipulate them each individually, or being able to look them up to manipulate them rather than trying to find their parent entity) would be beneficial.

1 decade ago by Manic

I ended up making this entity:

ig.module(
        'game.entities.loopingSoundManager'
)
.requires(
        'impact.entity'
)
.defines(function () {
        EntityLoopingSoundManager = ig.Entity.extend({
                ignorePause: true,
                
                sounds: [],
                stopped: false,
                
                add: function(sound) {
                        this.sounds.push(sound);
                        this.sounds[this.sounds.length-1].loop = true;
                        this.sounds[this.sounds.length-1].play();
                },
                
                stop: function() {
                        for (var i  = 0; i < this.sounds.length; i++) {
                                this.sounds[i].stop();
                        }
                },
                
                play: function() {
                        for (var i  = 0; i < this.sounds.length; i++) {
                                this.sounds[i].play();
                        }
                },
                
                init: function(x,y,settings) {
                        this.parent(x,y,settings);
                },
                
                update: function() {
                        this.parent();
                        if (ig.soundManager.volume <= 0) {
                                this.stop();
                                this.stopped = true;
                        } else if (this.stopped) {
                                this.play();
                                this.stopped = false;
                        }
                },
                
                loadLevel: function() {
                        this.stop();
                }
        });
});

For background, I&039;m using the pause plugin and another plugin I wrote to add a #loadLevel() function to all entities that gets called by ig.game.loadLevel() so that entities can wrap up stuff. This was mostly added to help with stopping looping sounds.

As you can see, this entity is used to store, mute, and stop looping sounds so that they don't keep on going forever. I don't know if there's a better way to do it.

1 decade ago by Joncom

@Manic: It might be a little cleaner to convert your entity to a class instead. I can't think of any functionality you might need in the entity class to accomplish what you are doing. It doesn't use physics for example. Or drawing. Etc.

1 decade ago by Manic

True. I think what I'm mostly trying to look for/think about making myself is a revamped sound library. Using the vanilla browser audio API means that you encounter all sorts of dumb side effects, like the looping of short clips with Chrome having a gap between iterations. Having an easy way to look up sounds, stop them, etc. would make a lot of sense for looping sounds.
Page 1 of 1
« first « previous next › last »