Impact

» Edit Game Info

3 years ago by sunnybubblegum

What is the best way to set up a repeating sound effect for the player's footsteps?

3 years ago by dominic

Browsers still suck at looping very short sound clips.

For the shooting sound in X-Type I made a few seconds long sound clip, playing it when the user starts shooting and ensure that it jumps back to the beginning when it reached the end through a callback, because some browsers don't understand the media's loop property (this may have changed in the last few months).

It's not pretty :/

var isShooting = ig.input.state('shoot');

// Did start shooting?
if( isShooting && !this.wasShooting ) {
	this.wasShooting = true;

	// Play the sound
	this.soundShoot.play();

	// Ensure that the callback is installed
	if( !this.soundShoot.currentClip.iloop ) {
		this.soundShoot.currentClip.iloop = true;
		this.soundShoot.currentClip.addEventListener( 'ended', (function(){
			this.currentTime = 0;
			this.play();
		}).bind(this.soundShoot.currentClip), false );
	}
}

// Did end shooting?
else if( this.wasShooting && !isShooting ) {
	this.soundShoot.stop();
	this.wasShooting = false;
}

ig.Sound is missing a 'loop' property that does this for you. I'll fix this in the next version!

3 years ago by sunnybubblegum

Thanks! This does it for now. I've got it working.
Will remove this workaround come the next version.

3 years ago by sunnybubblegum

The only issue I've been finding is this. Sometimes when I move my player to another room, if the footsteps sound was playing upon exiting the last room, it will continue looping infinitely in the new room. I thought if there was a way to 'stop all sounds' on the initialization of the level load this might help. What would be the best way to resolve this?
Page 1 of 1
« first « previous next › last »

Post Reply

Please login or register to reply.