@vpmedia/phaser 1.0.5 → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/phaser.cjs +1 -1
- package/dist/phaser.cjs.LICENSE.txt +1 -1
- package/dist/phaser.cjs.map +1 -1
- package/dist/phaser.js +1 -1
- package/dist/phaser.js.LICENSE.txt +1 -1
- package/dist/phaser.js.map +1 -1
- package/package.json +1 -1
- package/src/phaser/core/cache.js +2 -5
- package/src/phaser/core/device.js +0 -2
- package/src/phaser/core/device_util.js +0 -2
- package/src/phaser/core/loader.js +5 -43
- package/src/phaser/core/sound.js +13 -49
- package/src/phaser/core/sound_manager.js +40 -60
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vpmedia/phaser",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"description": "@vpmedia/phaser is the modern ECMAScript port of the popular Phaser game engine v2.6.2",
|
|
5
5
|
"author": "Andras Csizmadia <andras@vpmedia.hu> (www.vpmedia.hu)",
|
|
6
6
|
"license": "MIT",
|
package/src/phaser/core/cache.js
CHANGED
|
@@ -131,15 +131,12 @@ export default class {
|
|
|
131
131
|
this._resolveURL(url, obj);
|
|
132
132
|
}
|
|
133
133
|
|
|
134
|
-
addSound(key, url, data
|
|
135
|
-
const decoded = audioTag;
|
|
134
|
+
addSound(key, url, data) {
|
|
136
135
|
this._cache.sound[key] = {
|
|
137
136
|
url,
|
|
138
137
|
data,
|
|
139
138
|
isDecoding: false,
|
|
140
|
-
decoded,
|
|
141
|
-
webAudio,
|
|
142
|
-
audioTag,
|
|
139
|
+
decoded: false,
|
|
143
140
|
locked: this.game.sound.touchLocked,
|
|
144
141
|
};
|
|
145
142
|
this._resolveURL(url, this._cache.sound[key]);
|
|
@@ -232,8 +232,6 @@ export function checkVideo(device) {
|
|
|
232
232
|
* @param {object} device TBD
|
|
233
233
|
*/
|
|
234
234
|
export function checkAudio(device) {
|
|
235
|
-
device.audioData = !!(window.Audio);
|
|
236
|
-
device.webAudio = !!(window.AudioContext || window.webkitAudioContext);
|
|
237
235
|
const audioElement = document.createElement('audio');
|
|
238
236
|
try {
|
|
239
237
|
if (audioElement.canPlayType) {
|
|
@@ -627,12 +627,7 @@ export default class {
|
|
|
627
627
|
case 'audio':
|
|
628
628
|
file.url = this.getAudioURL(file.url);
|
|
629
629
|
if (file.url) {
|
|
630
|
-
|
|
631
|
-
if (this.game.sound.usingWebAudio) {
|
|
632
|
-
this.xhrLoad(file, this.transformUrl(file.url, file), 'arraybuffer', this.fileComplete);
|
|
633
|
-
} else if (this.game.sound.usingAudioTag) {
|
|
634
|
-
this.loadAudioTag(file);
|
|
635
|
-
}
|
|
630
|
+
this.xhrLoad(file, this.transformUrl(file.url, file), 'arraybuffer', this.fileComplete);
|
|
636
631
|
} else {
|
|
637
632
|
this.fileError(file, null, 'No supported audio URL specified or device does not have audio playback support');
|
|
638
633
|
}
|
|
@@ -716,35 +711,6 @@ export default class {
|
|
|
716
711
|
console.warn('loader.loadVideoTag() is not implemented');
|
|
717
712
|
}
|
|
718
713
|
|
|
719
|
-
loadAudioTag(file) {
|
|
720
|
-
const scope = this;
|
|
721
|
-
if (this.game.sound.touchLocked) {
|
|
722
|
-
// If audio is locked we can't do this yet, so need to queue this load request. Bum.
|
|
723
|
-
file.data = new Audio();
|
|
724
|
-
file.data.name = file.key;
|
|
725
|
-
file.data.preload = 'auto';
|
|
726
|
-
file.data.src = this.transformUrl(file.url, file);
|
|
727
|
-
this.fileComplete(file);
|
|
728
|
-
} else {
|
|
729
|
-
file.data = new Audio();
|
|
730
|
-
file.data.name = file.key;
|
|
731
|
-
const playThroughEvent = () => {
|
|
732
|
-
file.data.removeEventListener('canplaythrough', playThroughEvent, false);
|
|
733
|
-
file.data.onerror = null;
|
|
734
|
-
scope.fileComplete(file);
|
|
735
|
-
};
|
|
736
|
-
file.data.onerror = () => {
|
|
737
|
-
file.data.removeEventListener('canplaythrough', playThroughEvent, false);
|
|
738
|
-
file.data.onerror = null;
|
|
739
|
-
scope.fileError(file);
|
|
740
|
-
};
|
|
741
|
-
file.data.preload = 'auto';
|
|
742
|
-
file.data.src = this.transformUrl(file.url, file);
|
|
743
|
-
file.data.addEventListener('canplaythrough', playThroughEvent, false);
|
|
744
|
-
file.data.load();
|
|
745
|
-
}
|
|
746
|
-
}
|
|
747
|
-
|
|
748
714
|
xhrLoad(file, url, type, onload, onerror) {
|
|
749
715
|
const xhr = new XMLHttpRequest();
|
|
750
716
|
xhr.open('GET', url, true);
|
|
@@ -904,14 +870,10 @@ export default class {
|
|
|
904
870
|
this.cache.addVideo(file.key, file.url, file.data, file.asBlob);
|
|
905
871
|
break;
|
|
906
872
|
case 'audio':
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
this.game.sound.decode(file.key);
|
|
912
|
-
}
|
|
913
|
-
} else {
|
|
914
|
-
this.cache.addSound(file.key, file.url, file.data, false, true);
|
|
873
|
+
file.data = xhr.response;
|
|
874
|
+
this.cache.addSound(file.key, file.url, file.data);
|
|
875
|
+
if (file.autoDecode) {
|
|
876
|
+
this.game.sound.decode(file.key);
|
|
915
877
|
}
|
|
916
878
|
break;
|
|
917
879
|
case 'text':
|
package/src/phaser/core/sound.js
CHANGED
|
@@ -34,15 +34,13 @@ export default class {
|
|
|
34
34
|
this.pendingPlayback = false;
|
|
35
35
|
this.override = false;
|
|
36
36
|
this.allowMultiple = false;
|
|
37
|
-
this.usingWebAudio = this.game.sound.usingWebAudio;
|
|
38
|
-
this.usingAudioTag = this.game.sound.usingAudioTag;
|
|
39
37
|
this.externalNode = null;
|
|
40
38
|
this.masterGainNode = null;
|
|
41
39
|
this.gainNode = null;
|
|
42
40
|
this._sound = null;
|
|
43
41
|
this._markedToDelete = false;
|
|
44
42
|
this._removeFromSoundManager = false;
|
|
45
|
-
if (this.
|
|
43
|
+
if (!this.game.sound.noAudio) {
|
|
46
44
|
this.context = this.game.sound.context;
|
|
47
45
|
this.masterGainNode = this.game.sound.masterGain;
|
|
48
46
|
if (this.context.createGain === undefined) {
|
|
@@ -54,16 +52,6 @@ export default class {
|
|
|
54
52
|
if (connect) {
|
|
55
53
|
this.gainNode.connect(this.masterGainNode);
|
|
56
54
|
}
|
|
57
|
-
} else if (this.usingAudioTag) {
|
|
58
|
-
if (this.game.cache.getSound(key) && this.game.cache.isSoundReady(key)) {
|
|
59
|
-
this._sound = this.game.cache.getSoundData(key);
|
|
60
|
-
this.totalDuration = 0;
|
|
61
|
-
if (this._sound.duration) {
|
|
62
|
-
this.totalDuration = this._sound.duration;
|
|
63
|
-
}
|
|
64
|
-
} else {
|
|
65
|
-
this.game.cache.onSoundUnlock.add(this.soundHasUnlocked, this);
|
|
66
|
-
}
|
|
67
55
|
}
|
|
68
56
|
this.onDecoded = new Signal();
|
|
69
57
|
this.onPlay = new Signal();
|
|
@@ -158,7 +146,7 @@ export default class {
|
|
|
158
146
|
}
|
|
159
147
|
this.currentTime = this.game.time.time - this.startTime;
|
|
160
148
|
if (this.currentTime >= this.durationMS) {
|
|
161
|
-
if (this.
|
|
149
|
+
if (!this.game.sound.noAudio) {
|
|
162
150
|
if (this.loop) {
|
|
163
151
|
// won't work with markers, needs to reset the position
|
|
164
152
|
this.onLoop.dispatch(this);
|
|
@@ -204,7 +192,7 @@ export default class {
|
|
|
204
192
|
return this;
|
|
205
193
|
}
|
|
206
194
|
if (this._sound && this.isPlaying && !this.allowMultiple && (this.override || forceRestart)) {
|
|
207
|
-
if (this.
|
|
195
|
+
if (!this.game.sound.noAudio) {
|
|
208
196
|
if (this._sound.stop === undefined) {
|
|
209
197
|
this._sound.noteOff(0);
|
|
210
198
|
} else {
|
|
@@ -219,9 +207,6 @@ export default class {
|
|
|
219
207
|
} else if (this.gainNode) {
|
|
220
208
|
this._sound.disconnect(this.gainNode);
|
|
221
209
|
}
|
|
222
|
-
} else if (this.usingAudioTag) {
|
|
223
|
-
this._sound.pause();
|
|
224
|
-
this._sound.currentTime = 0;
|
|
225
210
|
}
|
|
226
211
|
this.isPlaying = false;
|
|
227
212
|
}
|
|
@@ -267,7 +252,7 @@ export default class {
|
|
|
267
252
|
this._tempVolume = volume;
|
|
268
253
|
this._tempLoop = loop;
|
|
269
254
|
}
|
|
270
|
-
if (this.
|
|
255
|
+
if (!this.game.sound.noAudio) {
|
|
271
256
|
// Does the sound need decoding?
|
|
272
257
|
if (this.game.cache.isSoundDecoded(this.key)) {
|
|
273
258
|
this._sound = this.context.createBufferSource();
|
|
@@ -354,7 +339,7 @@ export default class {
|
|
|
354
339
|
|
|
355
340
|
resume() {
|
|
356
341
|
if (this.paused && this._sound) {
|
|
357
|
-
if (this.
|
|
342
|
+
if (!this.game.sound.noAudio) {
|
|
358
343
|
const p = Math.max(0, this.position + (this.pausedPosition / 1000));
|
|
359
344
|
this._sound = this.context.createBufferSource();
|
|
360
345
|
this._sound.buffer = this._buffer;
|
|
@@ -383,9 +368,6 @@ export default class {
|
|
|
383
368
|
} else {
|
|
384
369
|
this._sound.start(0, p, duration);
|
|
385
370
|
}
|
|
386
|
-
} else {
|
|
387
|
-
this._sound.currentTime = this._tempPause;
|
|
388
|
-
this._sound.play();
|
|
389
371
|
}
|
|
390
372
|
this.isPlaying = true;
|
|
391
373
|
this.paused = false;
|
|
@@ -396,7 +378,7 @@ export default class {
|
|
|
396
378
|
|
|
397
379
|
stop() {
|
|
398
380
|
if (this.isPlaying && this._sound) {
|
|
399
|
-
if (this.
|
|
381
|
+
if (!this.game.sound.noAudio) {
|
|
400
382
|
if (this._sound.stop === undefined) {
|
|
401
383
|
this._sound.noteOff(0);
|
|
402
384
|
} else {
|
|
@@ -411,9 +393,6 @@ export default class {
|
|
|
411
393
|
} else if (this.gainNode) {
|
|
412
394
|
this._sound.disconnect(this.gainNode);
|
|
413
395
|
}
|
|
414
|
-
} else if (this.usingAudioTag) {
|
|
415
|
-
this._sound.pause();
|
|
416
|
-
this._sound.currentTime = 0;
|
|
417
396
|
}
|
|
418
397
|
}
|
|
419
398
|
this.pendingPlayback = false;
|
|
@@ -458,14 +437,6 @@ export default class {
|
|
|
458
437
|
}
|
|
459
438
|
}
|
|
460
439
|
|
|
461
|
-
updateGlobalVolume(globalVolume) {
|
|
462
|
-
// this._volume is the % of the global volume this sound should be played at
|
|
463
|
-
if (this.usingAudioTag && this._sound) {
|
|
464
|
-
this._sound.volume = globalVolume * this._volume;
|
|
465
|
-
}
|
|
466
|
-
|
|
467
|
-
}
|
|
468
|
-
|
|
469
440
|
destroy(remove = true) {
|
|
470
441
|
this._markedToDelete = true;
|
|
471
442
|
this._removeFromSoundManager = remove;
|
|
@@ -500,17 +471,13 @@ export default class {
|
|
|
500
471
|
if (value) {
|
|
501
472
|
this._muted = true;
|
|
502
473
|
this._muteVolume = this._tempVolume;
|
|
503
|
-
if (this.
|
|
474
|
+
if (!this.game.sound.noAudio) {
|
|
504
475
|
this.gainNode.gain.value = 0;
|
|
505
|
-
} else if (this.usingAudioTag && this._sound) {
|
|
506
|
-
this._sound.volume = 0;
|
|
507
476
|
}
|
|
508
477
|
} else {
|
|
509
478
|
this._muted = false;
|
|
510
|
-
if (this.
|
|
479
|
+
if (!this.game.sound.noAudio) {
|
|
511
480
|
this.gainNode.gain.value = this._muteVolume;
|
|
512
|
-
} else if (this.usingAudioTag && this._sound) {
|
|
513
|
-
this._sound.volume = this._muteVolume;
|
|
514
481
|
}
|
|
515
482
|
}
|
|
516
483
|
this.onMute.dispatch(this);
|
|
@@ -521,17 +488,14 @@ export default class {
|
|
|
521
488
|
}
|
|
522
489
|
|
|
523
490
|
set volume(value) {
|
|
524
|
-
const normalizedValue = this.usingAudioTag ? Math.max(0, Math.min(1, value)) : value;
|
|
525
491
|
if (this._muted) {
|
|
526
|
-
this._muteVolume =
|
|
492
|
+
this._muteVolume = value;
|
|
527
493
|
return;
|
|
528
494
|
}
|
|
529
|
-
this._tempVolume =
|
|
530
|
-
this._volume =
|
|
531
|
-
if (this.
|
|
532
|
-
this.gainNode.gain.value =
|
|
533
|
-
} else if (this.usingAudioTag && this._sound) {
|
|
534
|
-
this._sound.volume = normalizedValue;
|
|
495
|
+
this._tempVolume = value;
|
|
496
|
+
this._volume = value;
|
|
497
|
+
if (!this.game.sound.noAudio) {
|
|
498
|
+
this.gainNode.gain.value = value;
|
|
535
499
|
}
|
|
536
500
|
}
|
|
537
501
|
|
|
@@ -17,8 +17,6 @@ export default class {
|
|
|
17
17
|
this.onUnMute = new Signal();
|
|
18
18
|
this.context = null;
|
|
19
19
|
this.baseLatency = 0; // https://developer.mozilla.org/en-US/docs/Web/API/AudioContext/baseLatency
|
|
20
|
-
this.usingWebAudio = false;
|
|
21
|
-
this.usingAudioTag = false;
|
|
22
20
|
this.noAudio = false;
|
|
23
21
|
this.connectToMaster = true;
|
|
24
22
|
this.touchLocked = false;
|
|
@@ -42,7 +40,7 @@ export default class {
|
|
|
42
40
|
this.context = new window.AudioContext();
|
|
43
41
|
} catch (e) {
|
|
44
42
|
this.context = null;
|
|
45
|
-
this.
|
|
43
|
+
this.noAudio = true;
|
|
46
44
|
this.touchLocked = false;
|
|
47
45
|
}
|
|
48
46
|
} else if (window.webkitAudioContext) {
|
|
@@ -50,19 +48,13 @@ export default class {
|
|
|
50
48
|
this.context = new window.webkitAudioContext();
|
|
51
49
|
} catch (e) {
|
|
52
50
|
this.context = null;
|
|
53
|
-
this.
|
|
51
|
+
this.noAudio = true;
|
|
54
52
|
this.touchLocked = false;
|
|
55
53
|
}
|
|
56
54
|
}
|
|
57
55
|
if (this.context === null || (this.context && this.context.createGain === undefined && this.context.createGainNode === undefined)) {
|
|
58
|
-
|
|
59
|
-
if (window.Audio === undefined) {
|
|
60
|
-
this.noAudio = true;
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
this.usingAudioTag = true;
|
|
56
|
+
this.noAudio = true;
|
|
64
57
|
} else {
|
|
65
|
-
this.usingWebAudio = true;
|
|
66
58
|
this.baseLatency = this.context.baseLatency || (256 / (this.context.sampleRate || 44100));
|
|
67
59
|
if (this.context.createGain === undefined) {
|
|
68
60
|
this.masterGain = this.context.createGainNode();
|
|
@@ -71,45 +63,52 @@ export default class {
|
|
|
71
63
|
}
|
|
72
64
|
this.masterGain.gain.value = 1;
|
|
73
65
|
this.masterGain.connect(this.context.destination);
|
|
74
|
-
if (this.context.state === 'suspended') {
|
|
75
|
-
this.game.input.onUp.addOnce(this.resumeWebAudio, this);
|
|
76
|
-
}
|
|
77
66
|
}
|
|
78
|
-
if (
|
|
67
|
+
if (this.noAudio) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
if (this.game.device.iOS || this.game.device.android) {
|
|
79
71
|
this.game.input.addTouchLockCallback(this.unlock, this, true);
|
|
80
72
|
this.touchLocked = true;
|
|
81
73
|
}
|
|
82
74
|
}
|
|
83
75
|
|
|
84
|
-
|
|
85
|
-
if (this.
|
|
76
|
+
checkContextState() {
|
|
77
|
+
if (this.noAudio) {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
if (this.context.state === 'suspended') {
|
|
81
|
+
this.game.input.onUp.addOnce(this.resumeAudioContext, this);
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
resumeAudioContext() {
|
|
88
|
+
if (this.noAudio) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
if (this.context.state === 'suspended') {
|
|
86
92
|
this.context.resume();
|
|
87
93
|
}
|
|
88
94
|
}
|
|
89
95
|
|
|
90
96
|
unlock() {
|
|
91
|
-
if (
|
|
97
|
+
if (!this.touchLocked || this._unlockSource !== null) {
|
|
92
98
|
return true;
|
|
93
99
|
}
|
|
94
|
-
//
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
this._unlockSource.
|
|
104
|
-
this._unlockSource.connect(this.context.destination);
|
|
105
|
-
if (this._unlockSource.start === undefined) {
|
|
106
|
-
this._unlockSource.noteOn(0);
|
|
107
|
-
} else {
|
|
108
|
-
this._unlockSource.start(0);
|
|
109
|
-
}
|
|
110
|
-
this.resumeWebAudio();
|
|
100
|
+
// Create empty buffer and play it
|
|
101
|
+
// The SoundManager.update loop captures the state of it and then resets touchLocked to false
|
|
102
|
+
const buffer = this.context.createBuffer(1, 1, 22050);
|
|
103
|
+
this._unlockSource = this.context.createBufferSource();
|
|
104
|
+
this._unlockSource.buffer = buffer;
|
|
105
|
+
this._unlockSource.connect(this.context.destination);
|
|
106
|
+
if (this._unlockSource.start === undefined) {
|
|
107
|
+
this._unlockSource.noteOn(0);
|
|
108
|
+
} else {
|
|
109
|
+
this._unlockSource.start(0);
|
|
111
110
|
}
|
|
112
|
-
|
|
111
|
+
this.resumeAudioContext();
|
|
113
112
|
return true;
|
|
114
113
|
}
|
|
115
114
|
|
|
@@ -198,8 +197,8 @@ export default class {
|
|
|
198
197
|
if (this.touchLocked && this._unlockSource !== null && (this._unlockSource.playbackState === this._unlockSource.PLAYING_STATE || this._unlockSource.playbackState === this._unlockSource.FINISHED_STATE)) {
|
|
199
198
|
this.touchLocked = false;
|
|
200
199
|
this._unlockSource = null;
|
|
201
|
-
this.
|
|
202
|
-
} else if (this.
|
|
200
|
+
this.resumeAudioContext();
|
|
201
|
+
} else if (this.context.state === 'interrupted') {
|
|
203
202
|
this.context.resume();
|
|
204
203
|
}
|
|
205
204
|
for (let i = 0; i < this._sounds.length; i += 1) {
|
|
@@ -267,16 +266,10 @@ export default class {
|
|
|
267
266
|
return;
|
|
268
267
|
}
|
|
269
268
|
this._muted = true;
|
|
270
|
-
if (this.
|
|
269
|
+
if (!this.noAudio) {
|
|
271
270
|
this._muteVolume = this.masterGain.gain.value;
|
|
272
271
|
this.masterGain.gain.value = 0;
|
|
273
272
|
}
|
|
274
|
-
// Loop through sounds
|
|
275
|
-
for (let i = 0; i < this._sounds.length; i += 1) {
|
|
276
|
-
if (this._sounds[i].usingAudioTag) {
|
|
277
|
-
this._sounds[i].mute = true;
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
273
|
this.onMute.dispatch();
|
|
281
274
|
}
|
|
282
275
|
|
|
@@ -285,15 +278,9 @@ export default class {
|
|
|
285
278
|
return;
|
|
286
279
|
}
|
|
287
280
|
this._muted = false;
|
|
288
|
-
if (this.
|
|
281
|
+
if (!this.noAudio) {
|
|
289
282
|
this.masterGain.gain.value = this._muteVolume;
|
|
290
283
|
}
|
|
291
|
-
// Loop through sounds
|
|
292
|
-
for (let i = 0; i < this._sounds.length; i += 1) {
|
|
293
|
-
if (this._sounds[i].usingAudioTag) {
|
|
294
|
-
this._sounds[i].mute = false;
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
284
|
this.onUnMute.dispatch();
|
|
298
285
|
}
|
|
299
286
|
|
|
@@ -347,15 +334,8 @@ export default class {
|
|
|
347
334
|
}
|
|
348
335
|
if (this._volume !== value) {
|
|
349
336
|
this._volume = value;
|
|
350
|
-
if (this.
|
|
337
|
+
if (!this.noAudio) {
|
|
351
338
|
this.masterGain.gain.value = value;
|
|
352
|
-
} else {
|
|
353
|
-
// Loop through the sound cache and change the volume of all html audio tags
|
|
354
|
-
for (let i = 0; i < this._sounds.length; i += 1) {
|
|
355
|
-
if (this._sounds[i].usingAudioTag) {
|
|
356
|
-
this._sounds[i].updateGlobalVolume(value);
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
339
|
}
|
|
360
340
|
this.onVolumeChange.dispatch(value);
|
|
361
341
|
}
|