Skip to content

Commit 9c8f01c

Browse files
committed
The volume given in Sound.play now over-rides that set in Sound.addMarker if specified (fix phaserjs#623)
1 parent 51a2002 commit 9c8f01c

2 files changed

Lines changed: 17 additions & 12 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ Bug Fixes
9393
* If no seed was given in the Game config object, the RandomDataGenerator wouldn't be started (thank tylerjhutchison fix #619)
9494
* p2 revolute pivots were wrongly signed (thanks georgiee, fix #621)
9595
* P2.Body.loadPolygon no longer modifies the Cache array (fix #613)
96+
* The volume given in Sound.play now over-rides that set in Sound.addMarker if specified (fix #623)
9697

9798

9899
Updated

src/sound/Sound.js

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ Phaser.Sound.prototype = {
296296
*/
297297
addMarker: function (name, start, duration, volume, loop) {
298298

299-
volume = volume || 1;
299+
if (typeof volume == 'undefined') { volume = 1; }
300300
if (typeof loop == 'undefined') { loop = false; }
301301

302302
this.markers[name] = {
@@ -397,15 +397,9 @@ Phaser.Sound.prototype = {
397397
*/
398398
play: function (marker, position, volume, loop, forceRestart) {
399399

400-
marker = marker || '';
401-
position = position || 0;
402-
403-
if (typeof volume === 'undefined') { volume = this._volume; }
404-
if (typeof loop === 'undefined') { loop = this.loop; }
400+
if (typeof marker === 'undefined') { marker = ''; }
405401
if (typeof forceRestart === 'undefined') { forceRestart = true; }
406402

407-
// console.log(this.name + ' play ' + marker + ' position ' + position + ' volume ' + volume + ' loop ' + loop, 'force', forceRestart);
408-
409403
if (this.isPlaying === true && forceRestart === false && this.override === false)
410404
{
411405
// Use Restart instead
@@ -414,8 +408,6 @@ Phaser.Sound.prototype = {
414408

415409
if (this.isPlaying && this.override)
416410
{
417-
// console.log('asked to play ' + marker + ' but already playing ' + this.currentMarker);
418-
419411
if (this.usingWebAudio)
420412
{
421413
if (typeof this._sound.stop === 'undefined')
@@ -440,13 +432,22 @@ Phaser.Sound.prototype = {
440432
{
441433
if (this.markers[marker])
442434
{
435+
// Playing a marker? Then we default to the marker values
443436
this.position = this.markers[marker].start;
444437
this.volume = this.markers[marker].volume;
445438
this.loop = this.markers[marker].loop;
446439
this.duration = this.markers[marker].duration;
447440
this.durationMS = this.markers[marker].durationMS;
448441

449-
// console.log('Marker Loaded: ', marker, 'start:', this.position, 'end: ', this.duration, 'loop', this.loop);
442+
if (typeof volume !== 'undefined')
443+
{
444+
this.volume = volume;
445+
}
446+
447+
if (typeof loop !== 'undefined')
448+
{
449+
this.loop = loop;
450+
}
450451

451452
this._tempMarker = marker;
452453
this._tempPosition = this.position;
@@ -461,7 +462,10 @@ Phaser.Sound.prototype = {
461462
}
462463
else
463464
{
464-
// console.log('no marker info loaded', marker);
465+
position = position || 0;
466+
467+
if (typeof volume === 'undefined') { volume = this._volume; }
468+
if (typeof loop === 'undefined') { loop = this.loop; }
465469

466470
this.position = position;
467471
this.volume = volume;

0 commit comments

Comments
 (0)