@vpmedia/phaser 1.0.6 → 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 +0 -1
- package/src/phaser/core/device.js +0 -1
- package/src/phaser/core/device_util.js +0 -1
- package/src/phaser/core/sound.js +9 -13
- package/src/phaser/core/sound_manager.js +22 -15
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
|
@@ -232,7 +232,6 @@ export function checkVideo(device) {
|
|
|
232
232
|
* @param {object} device TBD
|
|
233
233
|
*/
|
|
234
234
|
export function checkAudio(device) {
|
|
235
|
-
device.webAudio = !!(window.AudioContext || window.webkitAudioContext);
|
|
236
235
|
const audioElement = document.createElement('audio');
|
|
237
236
|
try {
|
|
238
237
|
if (audioElement.canPlayType) {
|
package/src/phaser/core/sound.js
CHANGED
|
@@ -34,14 +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
37
|
this.externalNode = null;
|
|
39
38
|
this.masterGainNode = null;
|
|
40
39
|
this.gainNode = null;
|
|
41
40
|
this._sound = null;
|
|
42
41
|
this._markedToDelete = false;
|
|
43
42
|
this._removeFromSoundManager = false;
|
|
44
|
-
if (this.
|
|
43
|
+
if (!this.game.sound.noAudio) {
|
|
45
44
|
this.context = this.game.sound.context;
|
|
46
45
|
this.masterGainNode = this.game.sound.masterGain;
|
|
47
46
|
if (this.context.createGain === undefined) {
|
|
@@ -147,7 +146,7 @@ export default class {
|
|
|
147
146
|
}
|
|
148
147
|
this.currentTime = this.game.time.time - this.startTime;
|
|
149
148
|
if (this.currentTime >= this.durationMS) {
|
|
150
|
-
if (this.
|
|
149
|
+
if (!this.game.sound.noAudio) {
|
|
151
150
|
if (this.loop) {
|
|
152
151
|
// won't work with markers, needs to reset the position
|
|
153
152
|
this.onLoop.dispatch(this);
|
|
@@ -193,7 +192,7 @@ export default class {
|
|
|
193
192
|
return this;
|
|
194
193
|
}
|
|
195
194
|
if (this._sound && this.isPlaying && !this.allowMultiple && (this.override || forceRestart)) {
|
|
196
|
-
if (this.
|
|
195
|
+
if (!this.game.sound.noAudio) {
|
|
197
196
|
if (this._sound.stop === undefined) {
|
|
198
197
|
this._sound.noteOff(0);
|
|
199
198
|
} else {
|
|
@@ -253,7 +252,7 @@ export default class {
|
|
|
253
252
|
this._tempVolume = volume;
|
|
254
253
|
this._tempLoop = loop;
|
|
255
254
|
}
|
|
256
|
-
if (this.
|
|
255
|
+
if (!this.game.sound.noAudio) {
|
|
257
256
|
// Does the sound need decoding?
|
|
258
257
|
if (this.game.cache.isSoundDecoded(this.key)) {
|
|
259
258
|
this._sound = this.context.createBufferSource();
|
|
@@ -340,7 +339,7 @@ export default class {
|
|
|
340
339
|
|
|
341
340
|
resume() {
|
|
342
341
|
if (this.paused && this._sound) {
|
|
343
|
-
if (this.
|
|
342
|
+
if (!this.game.sound.noAudio) {
|
|
344
343
|
const p = Math.max(0, this.position + (this.pausedPosition / 1000));
|
|
345
344
|
this._sound = this.context.createBufferSource();
|
|
346
345
|
this._sound.buffer = this._buffer;
|
|
@@ -369,9 +368,6 @@ export default class {
|
|
|
369
368
|
} else {
|
|
370
369
|
this._sound.start(0, p, duration);
|
|
371
370
|
}
|
|
372
|
-
} else {
|
|
373
|
-
this._sound.currentTime = this._tempPause;
|
|
374
|
-
this._sound.play();
|
|
375
371
|
}
|
|
376
372
|
this.isPlaying = true;
|
|
377
373
|
this.paused = false;
|
|
@@ -382,7 +378,7 @@ export default class {
|
|
|
382
378
|
|
|
383
379
|
stop() {
|
|
384
380
|
if (this.isPlaying && this._sound) {
|
|
385
|
-
if (this.
|
|
381
|
+
if (!this.game.sound.noAudio) {
|
|
386
382
|
if (this._sound.stop === undefined) {
|
|
387
383
|
this._sound.noteOff(0);
|
|
388
384
|
} else {
|
|
@@ -475,12 +471,12 @@ export default class {
|
|
|
475
471
|
if (value) {
|
|
476
472
|
this._muted = true;
|
|
477
473
|
this._muteVolume = this._tempVolume;
|
|
478
|
-
if (this.
|
|
474
|
+
if (!this.game.sound.noAudio) {
|
|
479
475
|
this.gainNode.gain.value = 0;
|
|
480
476
|
}
|
|
481
477
|
} else {
|
|
482
478
|
this._muted = false;
|
|
483
|
-
if (this.
|
|
479
|
+
if (!this.game.sound.noAudio) {
|
|
484
480
|
this.gainNode.gain.value = this._muteVolume;
|
|
485
481
|
}
|
|
486
482
|
}
|
|
@@ -498,7 +494,7 @@ export default class {
|
|
|
498
494
|
}
|
|
499
495
|
this._tempVolume = value;
|
|
500
496
|
this._volume = value;
|
|
501
|
-
if (this.
|
|
497
|
+
if (!this.game.sound.noAudio) {
|
|
502
498
|
this.gainNode.gain.value = value;
|
|
503
499
|
}
|
|
504
500
|
}
|
|
@@ -17,7 +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
20
|
this.noAudio = false;
|
|
22
21
|
this.connectToMaster = true;
|
|
23
22
|
this.touchLocked = false;
|
|
@@ -41,7 +40,7 @@ export default class {
|
|
|
41
40
|
this.context = new window.AudioContext();
|
|
42
41
|
} catch (e) {
|
|
43
42
|
this.context = null;
|
|
44
|
-
this.
|
|
43
|
+
this.noAudio = true;
|
|
45
44
|
this.touchLocked = false;
|
|
46
45
|
}
|
|
47
46
|
} else if (window.webkitAudioContext) {
|
|
@@ -49,14 +48,13 @@ export default class {
|
|
|
49
48
|
this.context = new window.webkitAudioContext();
|
|
50
49
|
} catch (e) {
|
|
51
50
|
this.context = null;
|
|
52
|
-
this.
|
|
51
|
+
this.noAudio = true;
|
|
53
52
|
this.touchLocked = false;
|
|
54
53
|
}
|
|
55
54
|
}
|
|
56
55
|
if (this.context === null || (this.context && this.context.createGain === undefined && this.context.createGainNode === undefined)) {
|
|
57
56
|
this.noAudio = true;
|
|
58
57
|
} else {
|
|
59
|
-
this.usingWebAudio = true;
|
|
60
58
|
this.baseLatency = this.context.baseLatency || (256 / (this.context.sampleRate || 44100));
|
|
61
59
|
if (this.context.createGain === undefined) {
|
|
62
60
|
this.masterGain = this.context.createGainNode();
|
|
@@ -66,22 +64,31 @@ export default class {
|
|
|
66
64
|
this.masterGain.gain.value = 1;
|
|
67
65
|
this.masterGain.connect(this.context.destination);
|
|
68
66
|
}
|
|
69
|
-
if (this.
|
|
67
|
+
if (this.noAudio) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
if (this.game.device.iOS || this.game.device.android) {
|
|
70
71
|
this.game.input.addTouchLockCallback(this.unlock, this, true);
|
|
71
72
|
this.touchLocked = true;
|
|
72
73
|
}
|
|
73
74
|
}
|
|
74
75
|
|
|
75
76
|
checkContextState() {
|
|
76
|
-
if (this.
|
|
77
|
-
|
|
77
|
+
if (this.noAudio) {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
if (this.context.state === 'suspended') {
|
|
81
|
+
this.game.input.onUp.addOnce(this.resumeAudioContext, this);
|
|
78
82
|
return true;
|
|
79
83
|
}
|
|
80
84
|
return false;
|
|
81
85
|
}
|
|
82
86
|
|
|
83
|
-
|
|
84
|
-
if (this.
|
|
87
|
+
resumeAudioContext() {
|
|
88
|
+
if (this.noAudio) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
if (this.context.state === 'suspended') {
|
|
85
92
|
this.context.resume();
|
|
86
93
|
}
|
|
87
94
|
}
|
|
@@ -101,7 +108,7 @@ export default class {
|
|
|
101
108
|
} else {
|
|
102
109
|
this._unlockSource.start(0);
|
|
103
110
|
}
|
|
104
|
-
this.
|
|
111
|
+
this.resumeAudioContext();
|
|
105
112
|
return true;
|
|
106
113
|
}
|
|
107
114
|
|
|
@@ -190,8 +197,8 @@ export default class {
|
|
|
190
197
|
if (this.touchLocked && this._unlockSource !== null && (this._unlockSource.playbackState === this._unlockSource.PLAYING_STATE || this._unlockSource.playbackState === this._unlockSource.FINISHED_STATE)) {
|
|
191
198
|
this.touchLocked = false;
|
|
192
199
|
this._unlockSource = null;
|
|
193
|
-
this.
|
|
194
|
-
} else if (this.
|
|
200
|
+
this.resumeAudioContext();
|
|
201
|
+
} else if (this.context.state === 'interrupted') {
|
|
195
202
|
this.context.resume();
|
|
196
203
|
}
|
|
197
204
|
for (let i = 0; i < this._sounds.length; i += 1) {
|
|
@@ -259,7 +266,7 @@ export default class {
|
|
|
259
266
|
return;
|
|
260
267
|
}
|
|
261
268
|
this._muted = true;
|
|
262
|
-
if (this.
|
|
269
|
+
if (!this.noAudio) {
|
|
263
270
|
this._muteVolume = this.masterGain.gain.value;
|
|
264
271
|
this.masterGain.gain.value = 0;
|
|
265
272
|
}
|
|
@@ -271,7 +278,7 @@ export default class {
|
|
|
271
278
|
return;
|
|
272
279
|
}
|
|
273
280
|
this._muted = false;
|
|
274
|
-
if (this.
|
|
281
|
+
if (!this.noAudio) {
|
|
275
282
|
this.masterGain.gain.value = this._muteVolume;
|
|
276
283
|
}
|
|
277
284
|
this.onUnMute.dispatch();
|
|
@@ -327,7 +334,7 @@ export default class {
|
|
|
327
334
|
}
|
|
328
335
|
if (this._volume !== value) {
|
|
329
336
|
this._volume = value;
|
|
330
|
-
if (this.
|
|
337
|
+
if (!this.noAudio) {
|
|
331
338
|
this.masterGain.gain.value = value;
|
|
332
339
|
}
|
|
333
340
|
this.onVolumeChange.dispatch(value);
|