@vpmedia/phaser 1.94.0 → 1.96.0
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/CHANGELOG.md +41 -0
- package/package.json +11 -11
- package/src/phaser/core/animation.js +79 -56
- package/src/phaser/core/animation_manager.js +55 -55
- package/src/phaser/core/animation_parser.js +2 -2
- package/src/phaser/core/cache.js +154 -154
- package/src/phaser/core/device.js +2 -1
- package/src/phaser/core/device_util.js +27 -27
- package/src/phaser/core/dom.js +43 -43
- package/src/phaser/core/event_manager.js +63 -63
- package/src/phaser/core/factory.js +47 -47
- package/src/phaser/core/frame.js +30 -30
- package/src/phaser/core/frame_data.js +30 -28
- package/src/phaser/core/frame_util.js +8 -8
- package/src/phaser/core/game.js +35 -19
- package/src/phaser/core/input_pointer.js +18 -0
- package/src/phaser/core/loader.js +171 -171
- package/src/phaser/core/loader_parser.js +22 -22
- package/src/phaser/core/raf.js +1 -1
- package/src/phaser/core/scale_manager.js +3 -2
- package/src/phaser/core/scene.js +16 -10
- package/src/phaser/core/scene_manager.js +51 -43
- package/src/phaser/core/signal.js +56 -52
- package/src/phaser/core/sound.js +54 -54
- package/src/phaser/core/sound_manager.js +49 -49
- package/src/phaser/core/stage.js +16 -16
- package/src/phaser/core/time.js +54 -30
- package/src/phaser/core/timer.js +82 -64
- package/src/phaser/core/timer_event.js +9 -9
- package/src/phaser/core/tween.js +106 -90
- package/src/phaser/core/tween_data.js +30 -30
- package/src/phaser/core/tween_manager.js +32 -24
- package/src/phaser/core/world.js +4 -3
- package/src/phaser/display/bitmap_text.js +72 -54
- package/src/phaser/display/button.js +48 -47
- package/src/phaser/display/canvas/buffer.js +8 -8
- package/src/phaser/display/canvas/graphics.js +8 -8
- package/src/phaser/display/canvas/masker.js +5 -5
- package/src/phaser/display/canvas/pool.js +18 -18
- package/src/phaser/display/canvas/renderer.js +17 -16
- package/src/phaser/display/canvas/tinter.js +22 -22
- package/src/phaser/display/canvas/util.js +42 -42
- package/src/phaser/display/display_object.js +119 -108
- package/src/phaser/display/graphics.js +129 -112
- package/src/phaser/display/graphics_data.js +10 -10
- package/src/phaser/display/graphics_data_util.js +3 -3
- package/src/phaser/display/group.js +63 -50
- package/src/phaser/display/image.js +68 -50
- package/src/phaser/display/sprite_batch.js +2 -2
- package/src/phaser/display/sprite_util.js +19 -19
- package/src/phaser/display/text.js +217 -187
- package/src/phaser/display/webgl/abstract_filter.js +4 -4
- package/src/phaser/display/webgl/base_texture.js +9 -9
- package/src/phaser/display/webgl/blend_manager.js +7 -7
- package/src/phaser/display/webgl/earcut.js +95 -95
- package/src/phaser/display/webgl/earcut_node.js +4 -4
- package/src/phaser/display/webgl/fast_sprite_batch.js +15 -15
- package/src/phaser/display/webgl/filter_manager.js +9 -9
- package/src/phaser/display/webgl/filter_texture.js +10 -10
- package/src/phaser/display/webgl/graphics.js +37 -37
- package/src/phaser/display/webgl/graphics_data.js +4 -4
- package/src/phaser/display/webgl/mask_manager.js +6 -6
- package/src/phaser/display/webgl/render_texture.js +16 -16
- package/src/phaser/display/webgl/renderer.js +21 -20
- package/src/phaser/display/webgl/shader/complex.js +4 -4
- package/src/phaser/display/webgl/shader/fast.js +4 -4
- package/src/phaser/display/webgl/shader/normal.js +8 -8
- package/src/phaser/display/webgl/shader/primitive.js +4 -4
- package/src/phaser/display/webgl/shader/strip.js +4 -4
- package/src/phaser/display/webgl/shader_manager.js +9 -9
- package/src/phaser/display/webgl/sprite_batch.js +18 -18
- package/src/phaser/display/webgl/stencil_manager.js +16 -16
- package/src/phaser/display/webgl/texture.js +13 -13
- package/src/phaser/display/webgl/texture_util.js +8 -8
- package/src/phaser/display/webgl/util.js +25 -25
- package/src/phaser/geom/circle.js +74 -69
- package/src/phaser/geom/ellipse.js +33 -28
- package/src/phaser/geom/line.js +96 -93
- package/src/phaser/geom/matrix.js +61 -54
- package/src/phaser/geom/point.js +99 -96
- package/src/phaser/geom/polygon.js +27 -22
- package/src/phaser/geom/rectangle.js +137 -132
- package/src/phaser/geom/rounded_rectangle.js +12 -12
- package/src/phaser/geom/util/circle.js +33 -33
- package/src/phaser/geom/util/ellipse.js +5 -5
- package/src/phaser/geom/util/line.js +26 -26
- package/src/phaser/geom/util/matrix.js +8 -8
- package/src/phaser/geom/util/point.js +97 -97
- package/src/phaser/geom/util/polygon.js +4 -4
- package/src/phaser/geom/util/rectangle.js +74 -74
- package/src/phaser/geom/util/rounded_rectangle.js +4 -4
- package/src/phaser/util/math.js +81 -81
- package/types/phaser/core/animation.d.ts +79 -56
- package/types/phaser/core/animation.d.ts.map +1 -1
- package/types/phaser/core/animation_manager.d.ts +55 -55
- package/types/phaser/core/animation_parser.d.ts +3 -2
- package/types/phaser/core/animation_parser.d.ts.map +1 -1
- package/types/phaser/core/cache.d.ts +154 -154
- package/types/phaser/core/device.d.ts.map +1 -1
- package/types/phaser/core/dom.d.ts +51 -44
- package/types/phaser/core/dom.d.ts.map +1 -1
- package/types/phaser/core/event_manager.d.ts +63 -63
- package/types/phaser/core/factory.d.ts +47 -47
- package/types/phaser/core/frame.d.ts +30 -30
- package/types/phaser/core/frame_data.d.ts +28 -27
- package/types/phaser/core/frame_data.d.ts.map +1 -1
- package/types/phaser/core/game.d.ts +54 -21
- package/types/phaser/core/game.d.ts.map +1 -1
- package/types/phaser/core/input_pointer.d.ts +18 -0
- package/types/phaser/core/input_pointer.d.ts.map +1 -1
- package/types/phaser/core/loader.d.ts +175 -172
- package/types/phaser/core/loader.d.ts.map +1 -1
- package/types/phaser/core/loader_parser.d.ts.map +1 -1
- package/types/phaser/core/raf.d.ts +1 -1
- package/types/phaser/core/scale_manager.d.ts +6 -5
- package/types/phaser/core/scale_manager.d.ts.map +1 -1
- package/types/phaser/core/scene.d.ts +15 -9
- package/types/phaser/core/scene.d.ts.map +1 -1
- package/types/phaser/core/scene_manager.d.ts +51 -43
- package/types/phaser/core/scene_manager.d.ts.map +1 -1
- package/types/phaser/core/signal.d.ts +54 -51
- package/types/phaser/core/signal.d.ts.map +1 -1
- package/types/phaser/core/sound.d.ts +54 -54
- package/types/phaser/core/sound_manager.d.ts +49 -49
- package/types/phaser/core/stage.d.ts +10 -10
- package/types/phaser/core/time.d.ts +54 -30
- package/types/phaser/core/time.d.ts.map +1 -1
- package/types/phaser/core/timer.d.ts +82 -64
- package/types/phaser/core/timer.d.ts.map +1 -1
- package/types/phaser/core/timer_event.d.ts +9 -9
- package/types/phaser/core/tween.d.ts +106 -90
- package/types/phaser/core/tween.d.ts.map +1 -1
- package/types/phaser/core/tween_data.d.ts +30 -30
- package/types/phaser/core/tween_manager.d.ts +35 -67
- package/types/phaser/core/tween_manager.d.ts.map +1 -1
- package/types/phaser/core/world.d.ts +4 -3
- package/types/phaser/core/world.d.ts.map +1 -1
- package/types/phaser/display/bitmap_text.d.ts +76 -53
- package/types/phaser/display/bitmap_text.d.ts.map +1 -1
- package/types/phaser/display/button.d.ts +47 -46
- package/types/phaser/display/button.d.ts.map +1 -1
- package/types/phaser/display/canvas/buffer.d.ts +8 -8
- package/types/phaser/display/canvas/graphics.d.ts +3 -3
- package/types/phaser/display/canvas/graphics.d.ts.map +1 -1
- package/types/phaser/display/canvas/pool.d.ts +6 -3
- package/types/phaser/display/canvas/pool.d.ts.map +1 -1
- package/types/phaser/display/canvas/renderer.d.ts +18 -17
- package/types/phaser/display/canvas/renderer.d.ts.map +1 -1
- package/types/phaser/display/canvas/util.d.ts +6 -6
- package/types/phaser/display/canvas/util.d.ts.map +1 -1
- package/types/phaser/display/display_object.d.ts +119 -108
- package/types/phaser/display/display_object.d.ts.map +1 -1
- package/types/phaser/display/graphics.d.ts +118 -102
- package/types/phaser/display/graphics.d.ts.map +1 -1
- package/types/phaser/display/graphics_data.d.ts +10 -10
- package/types/phaser/display/group.d.ts +59 -47
- package/types/phaser/display/group.d.ts.map +1 -1
- package/types/phaser/display/image.d.ts +58 -45
- package/types/phaser/display/image.d.ts.map +1 -1
- package/types/phaser/display/text.d.ts +237 -188
- package/types/phaser/display/text.d.ts.map +1 -1
- package/types/phaser/display/webgl/abstract_filter.d.ts +4 -4
- package/types/phaser/display/webgl/base_texture.d.ts +10 -10
- package/types/phaser/display/webgl/base_texture.d.ts.map +1 -1
- package/types/phaser/display/webgl/blend_manager.d.ts +6 -6
- package/types/phaser/display/webgl/earcut.d.ts +95 -95
- package/types/phaser/display/webgl/earcut_node.d.ts +4 -4
- package/types/phaser/display/webgl/fast_sprite_batch.d.ts +15 -15
- package/types/phaser/display/webgl/filter_manager.d.ts +8 -8
- package/types/phaser/display/webgl/filter_texture.d.ts +10 -10
- package/types/phaser/display/webgl/graphics.d.ts +2 -2
- package/types/phaser/display/webgl/graphics.d.ts.map +1 -1
- package/types/phaser/display/webgl/graphics_data.d.ts +4 -4
- package/types/phaser/display/webgl/render_texture.d.ts +16 -16
- package/types/phaser/display/webgl/renderer.d.ts +21 -20
- package/types/phaser/display/webgl/renderer.d.ts.map +1 -1
- package/types/phaser/display/webgl/shader/complex.d.ts +4 -4
- package/types/phaser/display/webgl/shader/fast.d.ts +4 -4
- package/types/phaser/display/webgl/shader/normal.d.ts +8 -8
- package/types/phaser/display/webgl/shader/primitive.d.ts +4 -4
- package/types/phaser/display/webgl/shader/strip.d.ts +4 -4
- package/types/phaser/display/webgl/shader_manager.d.ts +8 -8
- package/types/phaser/display/webgl/sprite_batch.d.ts +17 -17
- package/types/phaser/display/webgl/stencil_manager.d.ts +15 -15
- package/types/phaser/display/webgl/texture.d.ts +12 -12
- package/types/phaser/display/webgl/texture_util.d.ts +4 -2
- package/types/phaser/display/webgl/texture_util.d.ts.map +1 -1
- package/types/phaser/geom/circle.d.ts +74 -69
- package/types/phaser/geom/circle.d.ts.map +1 -1
- package/types/phaser/geom/ellipse.d.ts +33 -28
- package/types/phaser/geom/ellipse.d.ts.map +1 -1
- package/types/phaser/geom/line.d.ts +96 -93
- package/types/phaser/geom/line.d.ts.map +1 -1
- package/types/phaser/geom/matrix.d.ts +61 -54
- package/types/phaser/geom/matrix.d.ts.map +1 -1
- package/types/phaser/geom/point.d.ts +99 -96
- package/types/phaser/geom/point.d.ts.map +1 -1
- package/types/phaser/geom/polygon.d.ts +29 -23
- package/types/phaser/geom/polygon.d.ts.map +1 -1
- package/types/phaser/geom/rectangle.d.ts +137 -132
- package/types/phaser/geom/rectangle.d.ts.map +1 -1
- package/types/phaser/geom/rounded_rectangle.d.ts +12 -12
- package/types/phaser/geom/util/point.d.ts +1 -1
- package/types/phaser/geom/util/point.d.ts.map +1 -1
- package/pnpm-workspace.yaml +0 -4
package/src/phaser/core/sound.js
CHANGED
|
@@ -2,12 +2,12 @@ import { Signal } from './signal.js';
|
|
|
2
2
|
|
|
3
3
|
export class Sound {
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
6
|
-
* @param {import('./game.js').Game} game -
|
|
7
|
-
* @param {string} key -
|
|
8
|
-
* @param {number} volume -
|
|
9
|
-
* @param {boolean} loop -
|
|
10
|
-
* @param {boolean} connect -
|
|
5
|
+
* Creates a new Sound instance.
|
|
6
|
+
* @param {import('./game.js').Game} game - Reference to the Phaser Game instance.
|
|
7
|
+
* @param {string} key - The key of the sound to play.
|
|
8
|
+
* @param {number} volume - The initial volume level (0.0 to 1.0).
|
|
9
|
+
* @param {boolean} loop - Whether the sound should loop.
|
|
10
|
+
* @param {boolean} connect - Whether to connect to the master gain node.
|
|
11
11
|
*/
|
|
12
12
|
constructor(game, key, volume = 1, loop = false, connect = null) {
|
|
13
13
|
// TODO
|
|
@@ -81,8 +81,8 @@ export class Sound {
|
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
/**
|
|
84
|
-
*
|
|
85
|
-
* @param {string} key -
|
|
84
|
+
* Callback when a sound has been unlocked.
|
|
85
|
+
* @param {string} key - The key of the sound that was unlocked.
|
|
86
86
|
*/
|
|
87
87
|
soundHasUnlocked(key) {
|
|
88
88
|
if (key === this.key) {
|
|
@@ -92,12 +92,12 @@ export class Sound {
|
|
|
92
92
|
}
|
|
93
93
|
|
|
94
94
|
/**
|
|
95
|
-
*
|
|
96
|
-
* @param {string} name -
|
|
97
|
-
* @param {number} start -
|
|
98
|
-
* @param {number} duration -
|
|
99
|
-
* @param {number} volume -
|
|
100
|
-
* @param {boolean} loop -
|
|
95
|
+
* Adds a marker to the sound.
|
|
96
|
+
* @param {string} name - The name of the marker.
|
|
97
|
+
* @param {number} start - The start time (in seconds) of the marker.
|
|
98
|
+
* @param {number} duration - The duration (in seconds) of the marker.
|
|
99
|
+
* @param {number} volume - The volume level (0.0 to 1.0) of the marker.
|
|
100
|
+
* @param {boolean} loop - Whether the marker should loop.
|
|
101
101
|
*/
|
|
102
102
|
addMarker(name, start, duration = 1, volume = 1, loop = false) {
|
|
103
103
|
this.markers[name] = {
|
|
@@ -112,15 +112,15 @@ export class Sound {
|
|
|
112
112
|
}
|
|
113
113
|
|
|
114
114
|
/**
|
|
115
|
-
*
|
|
116
|
-
* @param {string} name -
|
|
115
|
+
* Removes a marker from the sound.
|
|
116
|
+
* @param {string} name - The name of the marker to remove.
|
|
117
117
|
*/
|
|
118
118
|
removeMarker(name) {
|
|
119
119
|
delete this.markers[name];
|
|
120
120
|
}
|
|
121
121
|
|
|
122
122
|
/**
|
|
123
|
-
*
|
|
123
|
+
* Handler for when the sound ends.
|
|
124
124
|
*/
|
|
125
125
|
onEndedHandler() {
|
|
126
126
|
this._sound.onended = null;
|
|
@@ -154,7 +154,7 @@ export class Sound {
|
|
|
154
154
|
}
|
|
155
155
|
|
|
156
156
|
/**
|
|
157
|
-
*
|
|
157
|
+
* Updates the sound state.
|
|
158
158
|
*/
|
|
159
159
|
update() {
|
|
160
160
|
if (!this.game.cache.checkSoundKey(this.key)) {
|
|
@@ -191,22 +191,22 @@ export class Sound {
|
|
|
191
191
|
}
|
|
192
192
|
|
|
193
193
|
/**
|
|
194
|
-
*
|
|
195
|
-
* @param {number} volume -
|
|
196
|
-
* @returns {Sound}
|
|
194
|
+
* Plays the sound at full volume in a loop.
|
|
195
|
+
* @param {number} volume - The volume level (0.0 to 1.0) to play at.
|
|
196
|
+
* @returns {Sound} This Sound instance for chaining.
|
|
197
197
|
*/
|
|
198
198
|
loopFull(volume) {
|
|
199
199
|
return this.play(null, 0, volume, true);
|
|
200
200
|
}
|
|
201
201
|
|
|
202
202
|
/**
|
|
203
|
-
*
|
|
204
|
-
* @param {string} marker -
|
|
205
|
-
* @param {number} position -
|
|
206
|
-
* @param {number} volume -
|
|
207
|
-
* @param {boolean} loop -
|
|
208
|
-
* @param {boolean} forceRestart -
|
|
209
|
-
* @returns {Sound}
|
|
203
|
+
* Plays the sound, optionally using a marker.
|
|
204
|
+
* @param {string} marker - The name of the marker to play, or null/undefined to play the entire sound.
|
|
205
|
+
* @param {number} position - The position (in seconds) to start playing from.
|
|
206
|
+
* @param {number} volume - The volume level (0.0 to 1.0) to play at.
|
|
207
|
+
* @param {boolean} loop - Whether the sound should loop.
|
|
208
|
+
* @param {boolean} forceRestart - Whether to force restarting the sound even if it's already playing.
|
|
209
|
+
* @returns {Sound} This Sound instance for chaining.
|
|
210
210
|
*/
|
|
211
211
|
play(marker, position, volume, loop, forceRestart = true) {
|
|
212
212
|
if (marker === undefined || marker === false || marker === null) {
|
|
@@ -323,18 +323,18 @@ export class Sound {
|
|
|
323
323
|
}
|
|
324
324
|
|
|
325
325
|
/**
|
|
326
|
-
*
|
|
327
|
-
* @param {string} marker -
|
|
328
|
-
* @param {number} position -
|
|
329
|
-
* @param {number} volume -
|
|
330
|
-
* @param {boolean} loop -
|
|
326
|
+
* Restarts the sound, optionally using a marker.
|
|
327
|
+
* @param {string} marker - The name of the marker to play, or empty string to play the entire sound.
|
|
328
|
+
* @param {number} position - The position (in seconds) to start playing from.
|
|
329
|
+
* @param {number} volume - The volume level (0.0 to 1.0) to play at.
|
|
330
|
+
* @param {boolean} loop - Whether the sound should loop.
|
|
331
331
|
*/
|
|
332
332
|
restart(marker = '', position = 0, volume = 1, loop = false) {
|
|
333
333
|
this.play(marker, position, volume, loop, true);
|
|
334
334
|
}
|
|
335
335
|
|
|
336
336
|
/**
|
|
337
|
-
*
|
|
337
|
+
* Pauses the sound.
|
|
338
338
|
*/
|
|
339
339
|
pause() {
|
|
340
340
|
if (this.isPlaying && this._sound) {
|
|
@@ -348,7 +348,7 @@ export class Sound {
|
|
|
348
348
|
}
|
|
349
349
|
|
|
350
350
|
/**
|
|
351
|
-
*
|
|
351
|
+
* Resumes the sound.
|
|
352
352
|
*/
|
|
353
353
|
resume() {
|
|
354
354
|
if (this.paused && this._sound) {
|
|
@@ -380,7 +380,7 @@ export class Sound {
|
|
|
380
380
|
}
|
|
381
381
|
|
|
382
382
|
/**
|
|
383
|
-
*
|
|
383
|
+
* Stops the sound.
|
|
384
384
|
*/
|
|
385
385
|
stop() {
|
|
386
386
|
if (this.isPlaying && this._sound) {
|
|
@@ -411,10 +411,10 @@ export class Sound {
|
|
|
411
411
|
}
|
|
412
412
|
|
|
413
413
|
/**
|
|
414
|
-
*
|
|
415
|
-
* @param {number} duration -
|
|
416
|
-
* @param {boolean} loop -
|
|
417
|
-
* @param {string} marker -
|
|
414
|
+
* Fades in the sound to full volume.
|
|
415
|
+
* @param {number} duration - The fade-in duration (in milliseconds).
|
|
416
|
+
* @param {boolean} loop - Whether the sound should loop.
|
|
417
|
+
* @param {string} marker - The name of the marker to fade in, or empty string to use current marker.
|
|
418
418
|
*/
|
|
419
419
|
fadeIn(duration, loop = false, marker = this.currentMarker) {
|
|
420
420
|
if (this.paused) {
|
|
@@ -425,17 +425,17 @@ export class Sound {
|
|
|
425
425
|
}
|
|
426
426
|
|
|
427
427
|
/**
|
|
428
|
-
*
|
|
429
|
-
* @param {number} duration -
|
|
428
|
+
* Fades out the sound to silence.
|
|
429
|
+
* @param {number} duration - The fade-out duration (in milliseconds).
|
|
430
430
|
*/
|
|
431
431
|
fadeOut(duration) {
|
|
432
432
|
this.fadeTo(duration, 0);
|
|
433
433
|
}
|
|
434
434
|
|
|
435
435
|
/**
|
|
436
|
-
*
|
|
437
|
-
* @param {number} duration -
|
|
438
|
-
* @param {number} volume -
|
|
436
|
+
* Fades the sound to a specific volume level.
|
|
437
|
+
* @param {number} duration - The fade duration (in milliseconds).
|
|
438
|
+
* @param {number} volume - The target volume level (0.0 to 1.0).
|
|
439
439
|
*/
|
|
440
440
|
fadeTo(duration = 100, volume = 0) {
|
|
441
441
|
if (!this.isPlaying || this.paused || volume === this.volume) {
|
|
@@ -446,7 +446,7 @@ export class Sound {
|
|
|
446
446
|
}
|
|
447
447
|
|
|
448
448
|
/**
|
|
449
|
-
*
|
|
449
|
+
* Callback when fade completes.
|
|
450
450
|
*/
|
|
451
451
|
fadeComplete() {
|
|
452
452
|
this.onFadeComplete.dispatch(this, this.volume);
|
|
@@ -456,8 +456,8 @@ export class Sound {
|
|
|
456
456
|
}
|
|
457
457
|
|
|
458
458
|
/**
|
|
459
|
-
*
|
|
460
|
-
* @param {boolean} remove -
|
|
459
|
+
* Destroys the sound and cleans up resources.
|
|
460
|
+
* @param {boolean} remove - Whether to remove the sound from the SoundManager.
|
|
461
461
|
*/
|
|
462
462
|
destroy(remove = true) {
|
|
463
463
|
this._markedToDelete = true;
|
|
@@ -482,15 +482,15 @@ export class Sound {
|
|
|
482
482
|
}
|
|
483
483
|
|
|
484
484
|
/**
|
|
485
|
-
*
|
|
486
|
-
* @returns {boolean}
|
|
485
|
+
* Gets the muted state of the sound.
|
|
486
|
+
* @returns {boolean} True if the sound is muted, false otherwise.
|
|
487
487
|
*/
|
|
488
488
|
get mute() {
|
|
489
489
|
return this._muted || this.game.sound.mute;
|
|
490
490
|
}
|
|
491
491
|
|
|
492
492
|
/**
|
|
493
|
-
*
|
|
493
|
+
* Sets the muted state of the sound.
|
|
494
494
|
*/
|
|
495
495
|
set mute(value) {
|
|
496
496
|
value = value || false;
|
|
@@ -509,15 +509,15 @@ export class Sound {
|
|
|
509
509
|
}
|
|
510
510
|
|
|
511
511
|
/**
|
|
512
|
-
*
|
|
513
|
-
* @returns {number}
|
|
512
|
+
* Gets the volume of the sound.
|
|
513
|
+
* @returns {number} The volume level (0.0 to 1.0).
|
|
514
514
|
*/
|
|
515
515
|
get volume() {
|
|
516
516
|
return this._volume;
|
|
517
517
|
}
|
|
518
518
|
|
|
519
519
|
/**
|
|
520
|
-
*
|
|
520
|
+
* Sets the volume of the sound.
|
|
521
521
|
*/
|
|
522
522
|
set volume(value) {
|
|
523
523
|
if (this._muted) {
|
|
@@ -13,8 +13,8 @@ import { SoundSprite } from './sound_sprite.js';
|
|
|
13
13
|
|
|
14
14
|
export class SoundManager {
|
|
15
15
|
/**
|
|
16
|
-
*
|
|
17
|
-
* @param {import('./game.js').Game} game -
|
|
16
|
+
* Creates a new SoundManager instance.
|
|
17
|
+
* @param {import('./game.js').Game} game - Reference to the Phaser Game instance.
|
|
18
18
|
*/
|
|
19
19
|
constructor(game) {
|
|
20
20
|
this.game = game;
|
|
@@ -40,7 +40,7 @@ export class SoundManager {
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
/**
|
|
43
|
-
*
|
|
43
|
+
* Initializes the sound manager and sets up audio context.
|
|
44
44
|
*/
|
|
45
45
|
boot() {
|
|
46
46
|
const setAudioDisabledState = () => {
|
|
@@ -98,7 +98,7 @@ export class SoundManager {
|
|
|
98
98
|
}
|
|
99
99
|
|
|
100
100
|
/**
|
|
101
|
-
*
|
|
101
|
+
* Handles page lifecycle changes for audio management.
|
|
102
102
|
*/
|
|
103
103
|
onPageLifecycleChange = () => {
|
|
104
104
|
if (!document.hidden) {
|
|
@@ -107,7 +107,7 @@ export class SoundManager {
|
|
|
107
107
|
};
|
|
108
108
|
|
|
109
109
|
/**
|
|
110
|
-
*
|
|
110
|
+
* Handles audio context state changes.
|
|
111
111
|
*/
|
|
112
112
|
onContextStateChange = () => {
|
|
113
113
|
this.game.logger.info('onContextStateChange', {
|
|
@@ -118,7 +118,7 @@ export class SoundManager {
|
|
|
118
118
|
};
|
|
119
119
|
|
|
120
120
|
/**
|
|
121
|
-
*
|
|
121
|
+
* Checks if audio unlock handlers need to be added or removed.
|
|
122
122
|
*/
|
|
123
123
|
checkUnlockHandlers = () => {
|
|
124
124
|
this.game.logger.info('checkUnlockHandlers', {
|
|
@@ -133,7 +133,7 @@ export class SoundManager {
|
|
|
133
133
|
};
|
|
134
134
|
|
|
135
135
|
/**
|
|
136
|
-
*
|
|
136
|
+
* Adds event listeners to unlock audio context.
|
|
137
137
|
*/
|
|
138
138
|
addUnlockHandlers = () => {
|
|
139
139
|
this.isLocked = true;
|
|
@@ -147,7 +147,7 @@ export class SoundManager {
|
|
|
147
147
|
};
|
|
148
148
|
|
|
149
149
|
/**
|
|
150
|
-
*
|
|
150
|
+
* Removes event listeners that unlock audio context.
|
|
151
151
|
*/
|
|
152
152
|
removeUnlockHandlers = () => {
|
|
153
153
|
this.isLocked = false;
|
|
@@ -161,8 +161,8 @@ export class SoundManager {
|
|
|
161
161
|
};
|
|
162
162
|
|
|
163
163
|
/**
|
|
164
|
-
*
|
|
165
|
-
* @param {Event} event -
|
|
164
|
+
* Handles unlock events to resume audio context.
|
|
165
|
+
* @param {Event} event - The DOM event that triggered the unlock.
|
|
166
166
|
*/
|
|
167
167
|
onUnlockEvent = (event) => {
|
|
168
168
|
const initialState = this.context.state;
|
|
@@ -205,7 +205,7 @@ export class SoundManager {
|
|
|
205
205
|
};
|
|
206
206
|
|
|
207
207
|
/**
|
|
208
|
-
*
|
|
208
|
+
* Stops all sounds in the manager.
|
|
209
209
|
*/
|
|
210
210
|
stopAll() {
|
|
211
211
|
if (this.noAudio) {
|
|
@@ -219,7 +219,7 @@ export class SoundManager {
|
|
|
219
219
|
}
|
|
220
220
|
|
|
221
221
|
/**
|
|
222
|
-
*
|
|
222
|
+
* Pauses all sounds in the manager.
|
|
223
223
|
*/
|
|
224
224
|
pauseAll() {
|
|
225
225
|
if (this.noAudio) {
|
|
@@ -233,7 +233,7 @@ export class SoundManager {
|
|
|
233
233
|
}
|
|
234
234
|
|
|
235
235
|
/**
|
|
236
|
-
*
|
|
236
|
+
* Resumes all sounds in the manager.
|
|
237
237
|
*/
|
|
238
238
|
resumeAll() {
|
|
239
239
|
if (this.noAudio) {
|
|
@@ -247,8 +247,8 @@ export class SoundManager {
|
|
|
247
247
|
}
|
|
248
248
|
|
|
249
249
|
/**
|
|
250
|
-
*
|
|
251
|
-
* @param {string} key -
|
|
250
|
+
* Decodes an audio file for playback.
|
|
251
|
+
* @param {string} key - The key of the sound to decode.
|
|
252
252
|
*/
|
|
253
253
|
decode(key) {
|
|
254
254
|
const soundData = this.game.cache.getSoundData(key);
|
|
@@ -274,10 +274,10 @@ export class SoundManager {
|
|
|
274
274
|
}
|
|
275
275
|
|
|
276
276
|
/**
|
|
277
|
-
*
|
|
278
|
-
* @param {Sound[]|string[]} files -
|
|
279
|
-
* @param {Function} callback -
|
|
280
|
-
* @param {object} callbackContext -
|
|
277
|
+
* Sets up a callback to be called when audio files are decoded.
|
|
278
|
+
* @param {Sound[]|string[]} files - The sound files or keys to wait for.
|
|
279
|
+
* @param {Function} callback - The callback function to call when all files are decoded.
|
|
280
|
+
* @param {object} callbackContext - The context in which to call the callback.
|
|
281
281
|
*/
|
|
282
282
|
setDecodedCallback(files, callback, callbackContext) {
|
|
283
283
|
if (typeof files === 'string') {
|
|
@@ -306,7 +306,7 @@ export class SoundManager {
|
|
|
306
306
|
}
|
|
307
307
|
|
|
308
308
|
/**
|
|
309
|
-
*
|
|
309
|
+
* Updates the sound manager state.
|
|
310
310
|
*/
|
|
311
311
|
update() {
|
|
312
312
|
if (this.noAudio) {
|
|
@@ -332,12 +332,12 @@ export class SoundManager {
|
|
|
332
332
|
}
|
|
333
333
|
|
|
334
334
|
/**
|
|
335
|
-
*
|
|
336
|
-
* @param {string} key -
|
|
337
|
-
* @param {number} volume -
|
|
338
|
-
* @param {boolean} loop -
|
|
339
|
-
* @param {boolean} connect -
|
|
340
|
-
* @returns {Sound}
|
|
335
|
+
* Adds a new sound to the manager.
|
|
336
|
+
* @param {string} key - The key of the sound to add.
|
|
337
|
+
* @param {number} volume - The initial volume level (0.0 to 1.0).
|
|
338
|
+
* @param {boolean} loop - Whether the sound should loop.
|
|
339
|
+
* @param {boolean} connect - Whether to connect to the master gain node.
|
|
340
|
+
* @returns {Sound} The created Sound object.
|
|
341
341
|
*/
|
|
342
342
|
add(key, volume = 1, loop = false, connect = this.connectToMaster) {
|
|
343
343
|
const sound = new Sound(this.game, key, volume, loop, connect);
|
|
@@ -346,18 +346,18 @@ export class SoundManager {
|
|
|
346
346
|
}
|
|
347
347
|
|
|
348
348
|
/**
|
|
349
|
-
*
|
|
350
|
-
* @param {string} key -
|
|
351
|
-
* @returns {SoundSprite}
|
|
349
|
+
* Adds a new sound sprite to the manager.
|
|
350
|
+
* @param {string} key - The key of the sound sprite to add.
|
|
351
|
+
* @returns {SoundSprite} The created SoundSprite object.
|
|
352
352
|
*/
|
|
353
353
|
addSprite(key) {
|
|
354
354
|
return new SoundSprite(this.game, key);
|
|
355
355
|
}
|
|
356
356
|
|
|
357
357
|
/**
|
|
358
|
-
*
|
|
359
|
-
* @param {Sound | null | undefined} sound -
|
|
360
|
-
* @returns {boolean}
|
|
358
|
+
* Removes a sound from the manager.
|
|
359
|
+
* @param {Sound | null | undefined} sound - The sound object to remove.
|
|
360
|
+
* @returns {boolean} True if the sound was removed, false otherwise.
|
|
361
361
|
*/
|
|
362
362
|
remove(sound) {
|
|
363
363
|
let i = this._sounds.length;
|
|
@@ -373,9 +373,9 @@ export class SoundManager {
|
|
|
373
373
|
}
|
|
374
374
|
|
|
375
375
|
/**
|
|
376
|
-
*
|
|
377
|
-
* @param {string} key -
|
|
378
|
-
* @returns {number}
|
|
376
|
+
* Removes all sounds with a specific key from the manager.
|
|
377
|
+
* @param {string} key - The key of sounds to remove.
|
|
378
|
+
* @returns {number} The number of sounds removed.
|
|
379
379
|
*/
|
|
380
380
|
removeByKey(key) {
|
|
381
381
|
let i = this._sounds.length;
|
|
@@ -392,11 +392,11 @@ export class SoundManager {
|
|
|
392
392
|
}
|
|
393
393
|
|
|
394
394
|
/**
|
|
395
|
-
*
|
|
396
|
-
* @param {string} key -
|
|
397
|
-
* @param {number} volume -
|
|
398
|
-
* @param {boolean} loop -
|
|
399
|
-
* @returns {Sound}
|
|
395
|
+
* Plays a sound by key.
|
|
396
|
+
* @param {string} key - The key of the sound to play.
|
|
397
|
+
* @param {number} volume - The volume level (0.0 to 1.0).
|
|
398
|
+
* @param {boolean} loop - Whether the sound should loop.
|
|
399
|
+
* @returns {Sound} The created Sound object, or null if audio is disabled.
|
|
400
400
|
*/
|
|
401
401
|
play(key, volume = 1, loop = false) {
|
|
402
402
|
if (this.noAudio) {
|
|
@@ -408,7 +408,7 @@ export class SoundManager {
|
|
|
408
408
|
}
|
|
409
409
|
|
|
410
410
|
/**
|
|
411
|
-
*
|
|
411
|
+
* Mutes all sounds in the manager.
|
|
412
412
|
*/
|
|
413
413
|
setMute() {
|
|
414
414
|
if (this._muted) {
|
|
@@ -423,7 +423,7 @@ export class SoundManager {
|
|
|
423
423
|
}
|
|
424
424
|
|
|
425
425
|
/**
|
|
426
|
-
*
|
|
426
|
+
* Unmutes all sounds in the manager.
|
|
427
427
|
*/
|
|
428
428
|
unsetMute() {
|
|
429
429
|
if (!this._muted || this._codeMuted) {
|
|
@@ -437,7 +437,7 @@ export class SoundManager {
|
|
|
437
437
|
}
|
|
438
438
|
|
|
439
439
|
/**
|
|
440
|
-
*
|
|
440
|
+
* Destroys the sound manager and cleans up resources.
|
|
441
441
|
*/
|
|
442
442
|
destroy() {
|
|
443
443
|
this.stopAll();
|
|
@@ -454,15 +454,15 @@ export class SoundManager {
|
|
|
454
454
|
}
|
|
455
455
|
|
|
456
456
|
/**
|
|
457
|
-
*
|
|
458
|
-
* @returns {boolean}
|
|
457
|
+
* Gets the muted state of the sound manager.
|
|
458
|
+
* @returns {boolean} True if the manager is muted, false otherwise.
|
|
459
459
|
*/
|
|
460
460
|
get mute() {
|
|
461
461
|
return this._muted;
|
|
462
462
|
}
|
|
463
463
|
|
|
464
464
|
/**
|
|
465
|
-
*
|
|
465
|
+
* Sets the muted state of the sound manager.
|
|
466
466
|
*/
|
|
467
467
|
set mute(value) {
|
|
468
468
|
if (value || false) {
|
|
@@ -481,15 +481,15 @@ export class SoundManager {
|
|
|
481
481
|
}
|
|
482
482
|
|
|
483
483
|
/**
|
|
484
|
-
*
|
|
485
|
-
* @returns {number}
|
|
484
|
+
* Gets the volume level of the sound manager.
|
|
485
|
+
* @returns {number} The volume level (0.0 to 1.0).
|
|
486
486
|
*/
|
|
487
487
|
get volume() {
|
|
488
488
|
return this._volume;
|
|
489
489
|
}
|
|
490
490
|
|
|
491
491
|
/**
|
|
492
|
-
*
|
|
492
|
+
* Sets the volume level of the sound manager.
|
|
493
493
|
*/
|
|
494
494
|
set volume(value) {
|
|
495
495
|
if (value < 0) {
|
package/src/phaser/core/stage.js
CHANGED
|
@@ -6,8 +6,8 @@ import { SCALE_LINEAR, SCALE_NEAREST } from './const.js';
|
|
|
6
6
|
|
|
7
7
|
export class Stage extends DisplayObject {
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
10
|
-
* @param {import('./game.js').Game} game -
|
|
9
|
+
* Creates a new Stage instance.
|
|
10
|
+
* @param {import('./game.js').Game} game - The game instance.
|
|
11
11
|
*/
|
|
12
12
|
constructor(game) {
|
|
13
13
|
super(game);
|
|
@@ -32,8 +32,8 @@ export class Stage extends DisplayObject {
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
/**
|
|
35
|
-
*
|
|
36
|
-
* @param {number} color -
|
|
35
|
+
* Sets the background color of the stage.
|
|
36
|
+
* @param {number} color - The color to set as the background.
|
|
37
37
|
*/
|
|
38
38
|
setBackgroundColor(color) {
|
|
39
39
|
if (this.game.config.transparent) {
|
|
@@ -48,7 +48,7 @@ export class Stage extends DisplayObject {
|
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
/**
|
|
51
|
-
*
|
|
51
|
+
* Initializes the stage after game creation.
|
|
52
52
|
*/
|
|
53
53
|
boot() {
|
|
54
54
|
setUserSelect(this.game.canvas, 'none');
|
|
@@ -56,7 +56,7 @@ export class Stage extends DisplayObject {
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
/**
|
|
59
|
-
*
|
|
59
|
+
* Pre-updates the stage and its children.
|
|
60
60
|
*/
|
|
61
61
|
preUpdate() {
|
|
62
62
|
this.currentRenderOrderID = 0;
|
|
@@ -67,7 +67,7 @@ export class Stage extends DisplayObject {
|
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
/**
|
|
70
|
-
*
|
|
70
|
+
* Updates the stage and its children.
|
|
71
71
|
*/
|
|
72
72
|
update() {
|
|
73
73
|
let i = this.children.length;
|
|
@@ -78,7 +78,7 @@ export class Stage extends DisplayObject {
|
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
/**
|
|
81
|
-
*
|
|
81
|
+
* Post-updates the stage and its children.
|
|
82
82
|
*/
|
|
83
83
|
postUpdate() {
|
|
84
84
|
for (let i = 0; i < this.children.length; i += 1) {
|
|
@@ -88,7 +88,7 @@ export class Stage extends DisplayObject {
|
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
/**
|
|
91
|
-
*
|
|
91
|
+
* Updates the stage's transformation matrix.
|
|
92
92
|
*/
|
|
93
93
|
updateTransform() {
|
|
94
94
|
this.worldAlpha = 1;
|
|
@@ -98,7 +98,7 @@ export class Stage extends DisplayObject {
|
|
|
98
98
|
}
|
|
99
99
|
|
|
100
100
|
/**
|
|
101
|
-
*
|
|
101
|
+
* Destroys the stage and cleans up resources.
|
|
102
102
|
*/
|
|
103
103
|
destroy() {
|
|
104
104
|
this.exists = false;
|
|
@@ -108,30 +108,30 @@ export class Stage extends DisplayObject {
|
|
|
108
108
|
}
|
|
109
109
|
|
|
110
110
|
/**
|
|
111
|
-
*
|
|
112
|
-
* @returns {number}
|
|
111
|
+
* Gets the background color of the stage.
|
|
112
|
+
* @returns {number} The background color.
|
|
113
113
|
*/
|
|
114
114
|
get backgroundColor() {
|
|
115
115
|
return this._bgColor.color;
|
|
116
116
|
}
|
|
117
117
|
|
|
118
118
|
/**
|
|
119
|
-
*
|
|
119
|
+
* Sets the background color of the stage.
|
|
120
120
|
*/
|
|
121
121
|
set backgroundColor(value) {
|
|
122
122
|
this.setBackgroundColor(value);
|
|
123
123
|
}
|
|
124
124
|
|
|
125
125
|
/**
|
|
126
|
-
*
|
|
127
|
-
* @returns {boolean}
|
|
126
|
+
* Gets whether texture smoothing is enabled.
|
|
127
|
+
* @returns {boolean} True if texture smoothing is enabled, false otherwise.
|
|
128
128
|
*/
|
|
129
129
|
get smoothed() {
|
|
130
130
|
return window.PhaserRegistry.TEXTURE_SCALE_MODE === SCALE_LINEAR;
|
|
131
131
|
}
|
|
132
132
|
|
|
133
133
|
/**
|
|
134
|
-
*
|
|
134
|
+
* Sets whether texture smoothing is enabled.
|
|
135
135
|
*/
|
|
136
136
|
set smoothed(value) {
|
|
137
137
|
window.PhaserRegistry.TEXTURE_SCALE_MODE = value ? SCALE_LINEAR : SCALE_NEAREST;
|