so I’m trying to get my jump sound to play once per jump. Problem is, I cannot get it to still play the background music, but when activating any sound effect also playing that ONCE. and then when jumping again, resetting the old jump sound so it doesn’t overlap with the old sound effect. NOTE : that the only reason the functions have 'this.'
are because they are all contained within a central function that gets called as 'mylib = new functionNameHere ( );'
then the calls look like this :
'mylib.PlayAudio ({'
'currentSound : music [ 0 ]'
'});'
Here is the code I’m using :
this.AddAudio = function ( __objData )
{
__objData = __objData;
__snd = __objData.sound;
__key = __objData.key;
__config = __objData.config;
if ( typeof ( __objData ) !== 'object' ) { return console.error ( 'ERROR :: { Please ensure you are using an `object` for `objectData` & try again } !' ); }
__currentSound = __snd.add ( __key, __config );
return __currentSound;
}
this.PlayAudio = function ( __objData )
{
__objData = __objData;
__sound = __objData.sound;
__record = __objData.record;
if ( typeof ( __objData ) !== 'object' ) { return console.error ( 'ERROR :: { Please ensure you are using an `object` for `objectData` & try again } !' ); }
__oldSound = __currentSound;
if ( __oldSound.isPlaying === true ) {
this.StopAudio ({
currentSound : __currentSound,
});
/*
this.DestroyAudio ({
sound : __sound,
currentSound : __currentSound,
});
*/
__currentSound = this.AddAudio ({
sound : __sound,
key : __record.key,
config : __record.config,
});
__currentSound.play ( );
}
}
how it is called :
// Transition to jump if jump key{s} are pressed
if ( __isPlayerJumping === false && ( this.__keys.w.isDown || this.__keys.up.isDown ) )
{
__m.PlayAudio ({
scene : this.__scene,
sound : this.__sound,
record : __soundfx [ 0 ],
});
__JumpUp ({
stateMachine : this.__stateMachine,
keys : this.__keys,
scene : this.__scene,
entity : this.__entity,
minJumpHeightY : this.__minJumpHeightY,
maxJumpHeightY : this.__maxJumpHeightY,
minVelocityY : this.__minVelocityY,
maxVelocityY : this.__maxVelocityY,
minAccelerationY : this.__minAcclerationY,
maxAccelerationY : this.__maxAcclerationY,
});
}
if ( __m.isOnFloor ( this.__entity.body ) === true )
{
__isPlayerJumping = false;
__ActivateJump ({
stateMachine : this.stateMachine,
scene : this.__scene,
entity : this.__entity,
sound : this.__sound,
minJumpHeightY : this.__minJumpHeightY,
maxJumpHeightY : this.__maxJumpHeightY,
minVelocityY : this.__minVelocityY,
maxVelocityY : this.__maxVelocityY,
minAccelerationY : this.__minAccelerationY,
maxAccelerationY : this.__maxAccelerationY,
});
}
if ( __m.isOnFloor ( this.__entity.body ) === false )
{
__isPlayerJumping = true;
__ActivateFall ( {
stateMachine : this.stateMachine,
scene : this.__scene,
entity : this.__entity,
minVelocityY : this.__minVelocityY,
maxVelocityY : this.__maxVelocityY,
minAccelerationY : this.__minAccelerationY,
maxAccelerationY : this.__maxAccelerationY,
});
}
Here’s a small video of the issue :
Any help as always is GREATLY appreciated!
Thank You!!