@vpmedia/phaser 1.95.0 → 1.97.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 +51 -0
- package/package.json +10 -10
- package/src/phaser/core/animation.js +61 -56
- package/src/phaser/core/animation_manager.js +55 -55
- 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 +34 -18
- package/src/phaser/core/loader.js +170 -170
- package/src/phaser/core/loader_parser.js +22 -22
- package/src/phaser/core/raf.js +1 -1
- package/src/phaser/core/scene.js +16 -10
- package/src/phaser/core/scene_manager.js +51 -43
- package/src/phaser/core/signal.js +68 -52
- package/src/phaser/core/signal.test.js +37 -0
- 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 +30 -30
- package/src/phaser/core/timer.js +79 -64
- package/src/phaser/core/timer_event.js +9 -9
- package/src/phaser/core/tween.js +90 -90
- package/src/phaser/core/tween_data.js +30 -30
- package/src/phaser/core/tween_manager.js +29 -24
- package/src/phaser/core/world.js +4 -3
- package/src/phaser/display/bitmap_text.js +61 -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 +16 -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 +112 -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 +50 -50
- package/src/phaser/display/image.js +54 -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 +212 -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 +20 -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 +69 -69
- package/src/phaser/geom/circle.test.js +1 -0
- package/src/phaser/geom/ellipse.js +28 -28
- package/src/phaser/geom/ellipse.test.js +1 -0
- package/src/phaser/geom/line.js +93 -93
- package/src/phaser/geom/line.test.js +1 -0
- package/src/phaser/geom/matrix.js +54 -54
- package/src/phaser/geom/matrix.test.js +1 -0
- package/src/phaser/geom/point.js +96 -96
- package/src/phaser/geom/point.test.js +1 -0
- package/src/phaser/geom/polygon.js +22 -22
- package/src/phaser/geom/rectangle.js +132 -132
- package/src/phaser/geom/rectangle.test.js +1 -0
- package/src/phaser/geom/rounded_rectangle.js +12 -12
- package/src/phaser/geom/rounded_rectangle.test.js +1 -0
- package/src/phaser/geom/util/circle.js +33 -33
- package/src/phaser/geom/util/circle.test.js +1 -0
- package/src/phaser/geom/util/ellipse.js +5 -5
- package/src/phaser/geom/util/ellipse.test.js +1 -0
- package/src/phaser/geom/util/line.js +26 -26
- package/src/phaser/geom/util/line.test.js +1 -0
- package/src/phaser/geom/util/matrix.js +8 -8
- package/src/phaser/geom/util/matrix.test.js +1 -0
- package/src/phaser/geom/util/point.js +97 -97
- package/src/phaser/geom/util/point.test.js +1 -0
- package/src/phaser/geom/util/polygon.js +4 -4
- package/src/phaser/geom/util/polygon.test.js +1 -0
- package/src/phaser/geom/util/rectangle.js +74 -74
- package/src/phaser/geom/util/rectangle.test.js +1 -0
- package/src/phaser/geom/util/rounded_rectangle.js +4 -4
- package/src/phaser/geom/util/rounded_rectangle.test.js +1 -0
- package/src/phaser/util/math.js +81 -81
- package/src/phaser/util/math.test.js +1 -0
- package/types/phaser/core/animation.d.ts +61 -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/cache.d.ts +154 -154
- package/types/phaser/core/device.d.ts.map +1 -1
- package/types/phaser/core/dom.d.ts +43 -43
- 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 +52 -19
- package/types/phaser/core/game.d.ts.map +1 -1
- package/types/phaser/core/loader.d.ts +170 -170
- package/types/phaser/core/loader_parser.d.ts.map +1 -1
- package/types/phaser/core/raf.d.ts +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 +30 -30
- package/types/phaser/core/timer.d.ts +64 -64
- package/types/phaser/core/timer_event.d.ts +9 -9
- package/types/phaser/core/tween.d.ts +90 -90
- package/types/phaser/core/tween_data.d.ts +30 -30
- package/types/phaser/core/tween_manager.d.ts +29 -24
- 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 +59 -52
- 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/renderer.d.ts +16 -16
- 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 +101 -101
- package/types/phaser/display/graphics_data.d.ts +10 -10
- package/types/phaser/display/group.d.ts +47 -47
- package/types/phaser/display/image.d.ts +42 -40
- package/types/phaser/display/image.d.ts.map +1 -1
- package/types/phaser/display/text.d.ts +207 -184
- 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 +9 -9
- 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_data.d.ts +4 -4
- package/types/phaser/display/webgl/render_texture.d.ts +16 -16
- package/types/phaser/display/webgl/renderer.d.ts +20 -20
- 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/geom/circle.d.ts +69 -69
- package/types/phaser/geom/ellipse.d.ts +28 -28
- package/types/phaser/geom/line.d.ts +93 -93
- package/types/phaser/geom/matrix.d.ts +54 -54
- package/types/phaser/geom/point.d.ts +96 -96
- package/types/phaser/geom/polygon.d.ts +22 -22
- package/types/phaser/geom/rectangle.d.ts +132 -132
- package/types/phaser/geom/rounded_rectangle.d.ts +12 -12
- package/pnpm-workspace.yaml +0 -4
|
@@ -8,11 +8,11 @@ export const SORT_DESCENDING = 1;
|
|
|
8
8
|
|
|
9
9
|
export class Group extends DisplayObject {
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
12
|
-
* @param {import('../core/game.js').Game} game -
|
|
13
|
-
* @param {DisplayObject} parent -
|
|
14
|
-
* @param {string} name -
|
|
15
|
-
* @param {boolean} addToStage -
|
|
11
|
+
* Creates a new Group object.
|
|
12
|
+
* @param {import('../core/game.js').Game} game - The game instance this group belongs to.
|
|
13
|
+
* @param {DisplayObject} parent - The parent display object.
|
|
14
|
+
* @param {string} name - The name of this group.
|
|
15
|
+
* @param {boolean} addToStage - Whether to add this group to the stage.
|
|
16
16
|
*/
|
|
17
17
|
constructor(game, parent = null, name = null, addToStage = false) {
|
|
18
18
|
super(game);
|
|
@@ -57,9 +57,9 @@ export class Group extends DisplayObject {
|
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
/**
|
|
60
|
-
*
|
|
61
|
-
* @param {boolean} destroyChildren -
|
|
62
|
-
* @param {boolean} soft -
|
|
60
|
+
* Destroys this group and cleans up resources.
|
|
61
|
+
* @param {boolean} destroyChildren - Whether to destroy children as well.
|
|
62
|
+
* @param {boolean} soft - Whether to perform a soft destroy (leaving the group in the parent's children list).
|
|
63
63
|
*/
|
|
64
64
|
destroy(destroyChildren = true, soft = false) {
|
|
65
65
|
if (this.game === null || this.ignoreDestroy) {
|
|
@@ -80,11 +80,11 @@ export class Group extends DisplayObject {
|
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
/**
|
|
83
|
-
*
|
|
84
|
-
* @param {DisplayObject} child -
|
|
85
|
-
* @param {boolean} silent -
|
|
86
|
-
* @param {number} index -
|
|
87
|
-
* @returns {DisplayObject}
|
|
83
|
+
* Adds a child to this group.
|
|
84
|
+
* @param {DisplayObject} child - The child to add.
|
|
85
|
+
* @param {boolean} silent - Whether to dispatch events.
|
|
86
|
+
* @param {number} index - The index to add the child at.
|
|
87
|
+
* @returns {DisplayObject} The added child.
|
|
88
88
|
*/
|
|
89
89
|
add(child, silent = false, index = -1) {
|
|
90
90
|
if (child.parent === this) {
|
|
@@ -110,19 +110,19 @@ export class Group extends DisplayObject {
|
|
|
110
110
|
}
|
|
111
111
|
|
|
112
112
|
/**
|
|
113
|
-
*
|
|
114
|
-
* @param {DisplayObject} child -
|
|
115
|
-
* @param {number} index -
|
|
116
|
-
* @param {boolean} silent -
|
|
113
|
+
* Adds a child to this group at a specific index.
|
|
114
|
+
* @param {DisplayObject} child - The child to add.
|
|
115
|
+
* @param {number} index - The index to add the child at.
|
|
116
|
+
* @param {boolean} silent - Whether to dispatch events.
|
|
117
117
|
*/
|
|
118
118
|
addAt(child, index, silent) {
|
|
119
119
|
this.add(child, silent, index);
|
|
120
120
|
}
|
|
121
121
|
|
|
122
122
|
/**
|
|
123
|
-
*
|
|
124
|
-
* @param {number} index -
|
|
125
|
-
* @returns {DisplayObject}
|
|
123
|
+
* Gets a child at the specified index.
|
|
124
|
+
* @param {number} index - The index of the child to get.
|
|
125
|
+
* @returns {DisplayObject} The child at the specified index, or -1 if not found.
|
|
126
126
|
*/
|
|
127
127
|
getAt(index) {
|
|
128
128
|
if (index < 0 || index >= this.children.length) {
|
|
@@ -132,7 +132,7 @@ export class Group extends DisplayObject {
|
|
|
132
132
|
}
|
|
133
133
|
|
|
134
134
|
/**
|
|
135
|
-
*
|
|
135
|
+
* Updates the Z indices of all children in this group.
|
|
136
136
|
*/
|
|
137
137
|
updateZ() {
|
|
138
138
|
let i = this.children.length;
|
|
@@ -143,8 +143,8 @@ export class Group extends DisplayObject {
|
|
|
143
143
|
}
|
|
144
144
|
|
|
145
145
|
/**
|
|
146
|
-
*
|
|
147
|
-
* @returns {DisplayObject}
|
|
146
|
+
* Gets the next child in this group (with circular wrapping).
|
|
147
|
+
* @returns {DisplayObject} The next child, or null if no children exist.
|
|
148
148
|
*/
|
|
149
149
|
next() {
|
|
150
150
|
if (this.cursor) {
|
|
@@ -161,8 +161,8 @@ export class Group extends DisplayObject {
|
|
|
161
161
|
}
|
|
162
162
|
|
|
163
163
|
/**
|
|
164
|
-
*
|
|
165
|
-
* @returns {DisplayObject}
|
|
164
|
+
* Gets the previous child in this group (with circular wrapping).
|
|
165
|
+
* @returns {DisplayObject} The previous child, or null if no children exist.
|
|
166
166
|
*/
|
|
167
167
|
previous() {
|
|
168
168
|
if (this.cursor) {
|
|
@@ -179,9 +179,9 @@ export class Group extends DisplayObject {
|
|
|
179
179
|
}
|
|
180
180
|
|
|
181
181
|
/**
|
|
182
|
-
*
|
|
183
|
-
* @param {DisplayObject} child1 -
|
|
184
|
-
* @param {DisplayObject} child2 -
|
|
182
|
+
* Swaps the positions of two children in this group.
|
|
183
|
+
* @param {DisplayObject} child1 - The first child to swap.
|
|
184
|
+
* @param {DisplayObject} child2 - The second child to swap.
|
|
185
185
|
*/
|
|
186
186
|
swap(child1, child2) {
|
|
187
187
|
this.swapChildren(child1, child2);
|
|
@@ -189,9 +189,9 @@ export class Group extends DisplayObject {
|
|
|
189
189
|
}
|
|
190
190
|
|
|
191
191
|
/**
|
|
192
|
-
*
|
|
193
|
-
* @param {DisplayObject} child -
|
|
194
|
-
* @returns {DisplayObject}
|
|
192
|
+
* Brings a child to the top of this group.
|
|
193
|
+
* @param {DisplayObject} child - The child to bring to the top.
|
|
194
|
+
* @returns {DisplayObject} The child that was brought to the top.
|
|
195
195
|
*/
|
|
196
196
|
bringToTop(child) {
|
|
197
197
|
if (child.parent === this && this.getIndex(child) < this.children.length) {
|
|
@@ -202,9 +202,9 @@ export class Group extends DisplayObject {
|
|
|
202
202
|
}
|
|
203
203
|
|
|
204
204
|
/**
|
|
205
|
-
*
|
|
206
|
-
* @param {DisplayObject} child -
|
|
207
|
-
* @returns {DisplayObject}
|
|
205
|
+
* Sends a child to the back of this group.
|
|
206
|
+
* @param {DisplayObject} child - The child to send to the back.
|
|
207
|
+
* @returns {DisplayObject} The child that was sent to the back.
|
|
208
208
|
*/
|
|
209
209
|
sendToBack(child) {
|
|
210
210
|
if (child.parent === this && this.getIndex(child) > 0) {
|
|
@@ -215,7 +215,7 @@ export class Group extends DisplayObject {
|
|
|
215
215
|
}
|
|
216
216
|
|
|
217
217
|
/**
|
|
218
|
-
*
|
|
218
|
+
* Reverses the order of children in this group.
|
|
219
219
|
*/
|
|
220
220
|
reverse() {
|
|
221
221
|
this.children.reverse();
|
|
@@ -223,16 +223,16 @@ export class Group extends DisplayObject {
|
|
|
223
223
|
}
|
|
224
224
|
|
|
225
225
|
/**
|
|
226
|
-
*
|
|
227
|
-
* @param {DisplayObject} child -
|
|
228
|
-
* @returns {number}
|
|
226
|
+
* Gets the index of a child in this group.
|
|
227
|
+
* @param {DisplayObject} child - The child to get the index of.
|
|
228
|
+
* @returns {number} The index of the child, or -1 if not found.
|
|
229
229
|
*/
|
|
230
230
|
getIndex(child) {
|
|
231
231
|
return this.children.indexOf(child);
|
|
232
232
|
}
|
|
233
233
|
|
|
234
234
|
/**
|
|
235
|
-
*
|
|
235
|
+
* Updates the Z indices of all children in this group before the update cycle.
|
|
236
236
|
*/
|
|
237
237
|
preUpdate() {
|
|
238
238
|
if (this.pendingDestroy) {
|
|
@@ -249,7 +249,7 @@ export class Group extends DisplayObject {
|
|
|
249
249
|
}
|
|
250
250
|
|
|
251
251
|
/**
|
|
252
|
-
*
|
|
252
|
+
* Updates all children in this group during the update cycle.
|
|
253
253
|
*/
|
|
254
254
|
update() {
|
|
255
255
|
let i = this.children.length;
|
|
@@ -260,7 +260,7 @@ export class Group extends DisplayObject {
|
|
|
260
260
|
}
|
|
261
261
|
|
|
262
262
|
/**
|
|
263
|
-
*
|
|
263
|
+
* Updates all children in this group after the update cycle.
|
|
264
264
|
*/
|
|
265
265
|
postUpdate() {
|
|
266
266
|
for (let i = 0; i < this.children.length; i += 1) {
|
|
@@ -269,11 +269,11 @@ export class Group extends DisplayObject {
|
|
|
269
269
|
}
|
|
270
270
|
|
|
271
271
|
/**
|
|
272
|
-
*
|
|
273
|
-
* @param {DisplayObject} child -
|
|
274
|
-
* @param {boolean} destroy -
|
|
275
|
-
* @param {boolean} silent -
|
|
276
|
-
* @returns {boolean}
|
|
272
|
+
* Removes a child from this group.
|
|
273
|
+
* @param {DisplayObject} child - The child to remove.
|
|
274
|
+
* @param {boolean} destroy - Whether to destroy the child after removing it.
|
|
275
|
+
* @param {boolean} silent - Whether to dispatch events.
|
|
276
|
+
* @returns {boolean} True if the child was removed, false otherwise.
|
|
277
277
|
*/
|
|
278
278
|
remove(child, destroy = true, silent = false) {
|
|
279
279
|
if (this.children.length === 0 || this.children.indexOf(child) === -1) {
|
|
@@ -294,10 +294,10 @@ export class Group extends DisplayObject {
|
|
|
294
294
|
}
|
|
295
295
|
|
|
296
296
|
/**
|
|
297
|
-
*
|
|
298
|
-
* @param {boolean} destroy -
|
|
299
|
-
* @param {boolean} silent -
|
|
300
|
-
* @param {boolean} destroyTexture -
|
|
297
|
+
* Removes all children from this group.
|
|
298
|
+
* @param {boolean} destroy - Whether to destroy children as well.
|
|
299
|
+
* @param {boolean} silent - Whether to dispatch events.
|
|
300
|
+
* @param {boolean} destroyTexture - Whether to destroy textures as well.
|
|
301
301
|
*/
|
|
302
302
|
removeAll(destroy = true, silent = false, destroyTexture = false) {
|
|
303
303
|
if (this.children.length === 0) {
|
|
@@ -9,12 +9,12 @@ import { Texture } from './webgl/texture.js';
|
|
|
9
9
|
|
|
10
10
|
export class Image extends DisplayObject {
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
13
|
-
* @param {import('../core/game.js').Game} game -
|
|
14
|
-
* @param {number} x -
|
|
15
|
-
* @param {number} y -
|
|
16
|
-
* @param {string | number | Texture} key -
|
|
17
|
-
* @param {string | number} frame -
|
|
12
|
+
* Creates a new Image instance.
|
|
13
|
+
* @param {import('../core/game.js').Game} game - The game instance this image belongs to.
|
|
14
|
+
* @param {number} x - The x position of the image.
|
|
15
|
+
* @param {number} y - The y position of the image.
|
|
16
|
+
* @param {string | number | Texture} key - The texture key or texture to use.
|
|
17
|
+
* @param {string | number} frame - The frame identifier (name or index) to use.
|
|
18
18
|
*/
|
|
19
19
|
constructor(game, x, y, key, frame = 0) {
|
|
20
20
|
super(game);
|
|
@@ -57,7 +57,7 @@ export class Image extends DisplayObject {
|
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
/**
|
|
60
|
-
*
|
|
60
|
+
* Destroys this image and cleans up resources.
|
|
61
61
|
*/
|
|
62
62
|
destroy() {
|
|
63
63
|
this.game = null;
|
|
@@ -81,7 +81,7 @@ export class Image extends DisplayObject {
|
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
/**
|
|
84
|
-
*
|
|
84
|
+
* Called before the update cycle for this image.
|
|
85
85
|
*/
|
|
86
86
|
preUpdate() {
|
|
87
87
|
if (this.pendingDestroy) {
|
|
@@ -107,10 +107,10 @@ export class Image extends DisplayObject {
|
|
|
107
107
|
// LoadTexture
|
|
108
108
|
|
|
109
109
|
/**
|
|
110
|
-
*
|
|
111
|
-
* @param {string | number | Texture} key -
|
|
112
|
-
* @param {string | number | null | undefined} frame -
|
|
113
|
-
* @param {boolean} stopAnimation -
|
|
110
|
+
* Loads a texture for this image.
|
|
111
|
+
* @param {string | number | Texture} key - The texture key or texture to use.
|
|
112
|
+
* @param {string | number | null | undefined} frame - The frame identifier (name or index) to use.
|
|
113
|
+
* @param {boolean} stopAnimation - Whether to stop the animation when changing textures.
|
|
114
114
|
*/
|
|
115
115
|
loadTexture(key, frame = 0, stopAnimation = true) {
|
|
116
116
|
if (key === PENDING_ATLAS) {
|
|
@@ -151,8 +151,8 @@ export class Image extends DisplayObject {
|
|
|
151
151
|
}
|
|
152
152
|
|
|
153
153
|
/**
|
|
154
|
-
*
|
|
155
|
-
* @param {import('../core/frame.js').Frame} frame -
|
|
154
|
+
* Sets the current frame of this image.
|
|
155
|
+
* @param {import('../core/frame.js').Frame} frame - The frame to set.
|
|
156
156
|
*/
|
|
157
157
|
setFrame(frame) {
|
|
158
158
|
this._frame = frame;
|
|
@@ -196,10 +196,10 @@ export class Image extends DisplayObject {
|
|
|
196
196
|
}
|
|
197
197
|
|
|
198
198
|
/**
|
|
199
|
-
*
|
|
200
|
-
* @param {DisplayObject} parent -
|
|
201
|
-
* @param {number} width -
|
|
202
|
-
* @param {number} height -
|
|
199
|
+
* Resizes the frame of this image.
|
|
200
|
+
* @param {DisplayObject} parent - The parent display object.
|
|
201
|
+
* @param {number} width - The new width of the frame.
|
|
202
|
+
* @param {number} height - The new height of the frame.
|
|
203
203
|
*/
|
|
204
204
|
resizeFrame(parent, width, height) {
|
|
205
205
|
this.texture.frame.resize(width, height);
|
|
@@ -207,7 +207,7 @@ export class Image extends DisplayObject {
|
|
|
207
207
|
}
|
|
208
208
|
|
|
209
209
|
/**
|
|
210
|
-
*
|
|
210
|
+
* Resets the frame of this image to its original frame.
|
|
211
211
|
*/
|
|
212
212
|
resetFrame() {
|
|
213
213
|
if (this._frame) {
|
|
@@ -216,30 +216,32 @@ export class Image extends DisplayObject {
|
|
|
216
216
|
}
|
|
217
217
|
|
|
218
218
|
/**
|
|
219
|
-
*
|
|
220
|
-
* @returns {number}
|
|
219
|
+
* Gets the current frame index of this image.
|
|
220
|
+
* @returns {number} The current frame index.
|
|
221
221
|
*/
|
|
222
222
|
get frame() {
|
|
223
223
|
return this.animations.frame;
|
|
224
224
|
}
|
|
225
225
|
|
|
226
226
|
/**
|
|
227
|
-
*
|
|
227
|
+
* Sets the current frame index of this image.
|
|
228
|
+
* @param {number} value - The new frame index to set.
|
|
228
229
|
*/
|
|
229
230
|
set frame(value) {
|
|
230
231
|
this.animations.frame = value;
|
|
231
232
|
}
|
|
232
233
|
|
|
233
234
|
/**
|
|
234
|
-
*
|
|
235
|
-
* @returns {string}
|
|
235
|
+
* Gets the current frame name of this image.
|
|
236
|
+
* @returns {string} The current frame name.
|
|
236
237
|
*/
|
|
237
238
|
get frameName() {
|
|
238
239
|
return this.animations.frameName;
|
|
239
240
|
}
|
|
240
241
|
|
|
241
242
|
/**
|
|
242
|
-
*
|
|
243
|
+
* Sets the current frame name of this image.
|
|
244
|
+
* @param {string} value - The new frame name to set.
|
|
243
245
|
*/
|
|
244
246
|
set frameName(value) {
|
|
245
247
|
this.animations.frameName = value;
|
|
@@ -248,9 +250,9 @@ export class Image extends DisplayObject {
|
|
|
248
250
|
// Crop
|
|
249
251
|
|
|
250
252
|
/**
|
|
251
|
-
*
|
|
252
|
-
* @param {Rectangle} rect -
|
|
253
|
-
* @param {boolean} copy -
|
|
253
|
+
* Crops the texture of this image.
|
|
254
|
+
* @param {Rectangle} rect - The rectangle to crop to.
|
|
255
|
+
* @param {boolean} copy - Whether to copy the rect or use it directly.
|
|
254
256
|
*/
|
|
255
257
|
crop(rect, copy = false) {
|
|
256
258
|
if (rect) {
|
|
@@ -270,7 +272,7 @@ export class Image extends DisplayObject {
|
|
|
270
272
|
}
|
|
271
273
|
|
|
272
274
|
/**
|
|
273
|
-
*
|
|
275
|
+
* Updates the crop rectangle of this image.
|
|
274
276
|
*/
|
|
275
277
|
updateCrop() {
|
|
276
278
|
if (!this.cropRect) {
|
|
@@ -302,15 +304,16 @@ export class Image extends DisplayObject {
|
|
|
302
304
|
}
|
|
303
305
|
|
|
304
306
|
/**
|
|
305
|
-
*
|
|
306
|
-
* @returns {number}
|
|
307
|
+
* Gets the width of this image.
|
|
308
|
+
* @returns {number} The width in pixels.
|
|
307
309
|
*/
|
|
308
310
|
get width() {
|
|
309
311
|
return this.scale.x * this.texture.frame.width;
|
|
310
312
|
}
|
|
311
313
|
|
|
312
314
|
/**
|
|
313
|
-
*
|
|
315
|
+
* Sets the width of this image.
|
|
316
|
+
* @param {number} value - The new width in pixels.
|
|
314
317
|
*/
|
|
315
318
|
set width(value) {
|
|
316
319
|
this.scale.x = value / this.texture.frame.width;
|
|
@@ -318,15 +321,16 @@ export class Image extends DisplayObject {
|
|
|
318
321
|
}
|
|
319
322
|
|
|
320
323
|
/**
|
|
321
|
-
*
|
|
322
|
-
* @returns {number}
|
|
324
|
+
* Gets the height of this image.
|
|
325
|
+
* @returns {number} The height in pixels.
|
|
323
326
|
*/
|
|
324
327
|
get height() {
|
|
325
328
|
return this.scale.y * this.texture.frame.height;
|
|
326
329
|
}
|
|
327
330
|
|
|
328
331
|
/**
|
|
329
|
-
*
|
|
332
|
+
* Sets the height of this image.
|
|
333
|
+
* @param {number} value - The new height in pixels.
|
|
330
334
|
*/
|
|
331
335
|
set height(value) {
|
|
332
336
|
this.scale.y = value / this.texture.frame.height;
|
|
@@ -334,7 +338,7 @@ export class Image extends DisplayObject {
|
|
|
334
338
|
}
|
|
335
339
|
|
|
336
340
|
/**
|
|
337
|
-
*
|
|
341
|
+
* Called when the texture of this image is updated.
|
|
338
342
|
*/
|
|
339
343
|
onTextureUpdate() {
|
|
340
344
|
// so if _width is 0 then width was not set..
|
|
@@ -347,44 +351,44 @@ export class Image extends DisplayObject {
|
|
|
347
351
|
}
|
|
348
352
|
|
|
349
353
|
/**
|
|
350
|
-
*
|
|
351
|
-
* @param {Texture} texture -
|
|
352
|
-
* @param {boolean} destroyBase -
|
|
354
|
+
* Sets the texture for this image.
|
|
355
|
+
* @param {Texture} texture - The new texture to set.
|
|
356
|
+
* @param {boolean} destroyBase - Whether to destroy the base texture.
|
|
353
357
|
*/
|
|
354
358
|
setTexture(texture, destroyBase = false) {
|
|
355
359
|
setTexture(this, texture, destroyBase);
|
|
356
360
|
}
|
|
357
361
|
|
|
358
362
|
/**
|
|
359
|
-
*
|
|
360
|
-
* @param {import('../geom/matrix.js').Matrix} matrix -
|
|
361
|
-
* @returns {Rectangle}
|
|
363
|
+
* Gets the bounds of this image.
|
|
364
|
+
* @param {import('../geom/matrix.js').Matrix} matrix - The transformation matrix to use.
|
|
365
|
+
* @returns {Rectangle} The bounds rectangle of this image.
|
|
362
366
|
*/
|
|
363
367
|
getBounds(matrix = null) {
|
|
364
368
|
return getBounds(this, matrix);
|
|
365
369
|
}
|
|
366
370
|
|
|
367
371
|
/**
|
|
368
|
-
*
|
|
369
|
-
* @returns {Rectangle}
|
|
372
|
+
* Gets the local bounds of this image.
|
|
373
|
+
* @returns {Rectangle} The local bounds rectangle of this image.
|
|
370
374
|
*/
|
|
371
375
|
getLocalBounds() {
|
|
372
376
|
return getLocalBounds(this);
|
|
373
377
|
}
|
|
374
378
|
|
|
375
379
|
/**
|
|
376
|
-
*
|
|
377
|
-
* @param {object} renderSession -
|
|
378
|
-
* @param {import('../geom/matrix.js').Matrix} matrix -
|
|
380
|
+
* Renders this image using WebGL.
|
|
381
|
+
* @param {object} renderSession - The WebGL rendering session.
|
|
382
|
+
* @param {import('../geom/matrix.js').Matrix} matrix - The transformation matrix to use.
|
|
379
383
|
*/
|
|
380
384
|
renderWebGL(renderSession, matrix = null) {
|
|
381
385
|
renderWebGL(this, renderSession, matrix);
|
|
382
386
|
}
|
|
383
387
|
|
|
384
388
|
/**
|
|
385
|
-
*
|
|
386
|
-
* @param {object} renderSession -
|
|
387
|
-
* @param {import('../geom/matrix.js').Matrix} matrix -
|
|
389
|
+
* Renders this image using Canvas.
|
|
390
|
+
* @param {object} renderSession - The Canvas rendering session.
|
|
391
|
+
* @param {import('../geom/matrix.js').Matrix} matrix - The transformation matrix to use.
|
|
388
392
|
*/
|
|
389
393
|
renderCanvas(renderSession, matrix = null) {
|
|
390
394
|
renderCanvas(this, renderSession, matrix);
|
|
@@ -2,8 +2,8 @@ import { DisplayObject } from './display_object.js';
|
|
|
2
2
|
|
|
3
3
|
export class SpriteBatch extends DisplayObject {
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
6
|
-
* @param {import('../core/game.js').Game} game -
|
|
5
|
+
* Creates a new SpriteBatch object.
|
|
6
|
+
* @param {import('../core/game.js').Game} game - The game instance.
|
|
7
7
|
*/
|
|
8
8
|
constructor(game) {
|
|
9
9
|
super(game);
|
|
@@ -3,10 +3,10 @@ import { getIdentityMatrix } from '../geom/util/matrix.js';
|
|
|
3
3
|
import { getTintedTexture } from './canvas/tinter.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
* @param {import('./image.js').Image} target -
|
|
8
|
-
* @param {import('./webgl/texture.js').Texture} texture -
|
|
9
|
-
* @param {boolean} destroyBase -
|
|
6
|
+
* Sets the texture of a sprite.
|
|
7
|
+
* @param {import('./image.js').Image} target - The target image to set the texture on.
|
|
8
|
+
* @param {import('./webgl/texture.js').Texture} texture - The new texture to set.
|
|
9
|
+
* @param {boolean} destroyBase - Whether to destroy the base texture.
|
|
10
10
|
*/
|
|
11
11
|
export const setTexture = (target, texture, destroyBase = false) => {
|
|
12
12
|
if (destroyBase) {
|
|
@@ -19,10 +19,10 @@ export const setTexture = (target, texture, destroyBase = false) => {
|
|
|
19
19
|
};
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
|
-
*
|
|
23
|
-
* @param {import('./image.js').Image} target -
|
|
24
|
-
* @param {object} matrix -
|
|
25
|
-
* @returns {import('../geom/rectangle.js').Rectangle}
|
|
22
|
+
* Gets the bounds of a sprite.
|
|
23
|
+
* @param {import('./image.js').Image} target - The target image to get bounds for.
|
|
24
|
+
* @param {object} matrix - The transformation matrix.
|
|
25
|
+
* @returns {import('../geom/rectangle.js').Rectangle} The bounds rectangle.
|
|
26
26
|
*/
|
|
27
27
|
export const getBounds = (target, matrix = null) => {
|
|
28
28
|
// TODO verify
|
|
@@ -102,9 +102,9 @@ export const getBounds = (target, matrix = null) => {
|
|
|
102
102
|
};
|
|
103
103
|
|
|
104
104
|
/**
|
|
105
|
-
*
|
|
106
|
-
* @param {import('./image.js').Image} target -
|
|
107
|
-
* @returns {import('../geom/rectangle.js').Rectangle}
|
|
105
|
+
* Gets the local bounds of a sprite.
|
|
106
|
+
* @param {import('./image.js').Image} target - The target image to get local bounds for.
|
|
107
|
+
* @returns {import('../geom/rectangle.js').Rectangle} The local bounds rectangle.
|
|
108
108
|
*/
|
|
109
109
|
export const getLocalBounds = (target) => {
|
|
110
110
|
const matrixCache = target.worldTransform;
|
|
@@ -122,10 +122,10 @@ export const getLocalBounds = (target) => {
|
|
|
122
122
|
};
|
|
123
123
|
|
|
124
124
|
/**
|
|
125
|
-
*
|
|
126
|
-
* @param {import('./image.js').Image} target -
|
|
127
|
-
* @param {object} renderSession -
|
|
128
|
-
* @param {import('../geom/matrix.js').Matrix | null | undefined} matrix -
|
|
125
|
+
* Renders a sprite using WebGL.
|
|
126
|
+
* @param {import('./image.js').Image} target - The target image to render.
|
|
127
|
+
* @param {object} renderSession - The render session object.
|
|
128
|
+
* @param {import('../geom/matrix.js').Matrix | null | undefined} matrix - The transformation matrix.
|
|
129
129
|
*/
|
|
130
130
|
export const renderWebGL = (target, renderSession, matrix = null) => {
|
|
131
131
|
// if the sprite is not visible or the alpha is 0 then no need to render this element
|
|
@@ -171,10 +171,10 @@ export const renderWebGL = (target, renderSession, matrix = null) => {
|
|
|
171
171
|
};
|
|
172
172
|
|
|
173
173
|
/**
|
|
174
|
-
*
|
|
175
|
-
* @param {import('./image.js').Image} target -
|
|
176
|
-
* @param {object} renderSession -
|
|
177
|
-
* @param {import('../geom/matrix.js').Matrix | null | undefined} matrix -
|
|
174
|
+
* Renders a sprite using Canvas.
|
|
175
|
+
* @param {import('./image.js').Image} target - The target image to render.
|
|
176
|
+
* @param {object} renderSession - The render session object.
|
|
177
|
+
* @param {import('../geom/matrix.js').Matrix | null | undefined} matrix - The transformation matrix.
|
|
178
178
|
*/
|
|
179
179
|
export const renderCanvas = (target, renderSession, matrix = null) => {
|
|
180
180
|
// If the sprite is not visible or the alpha is 0 then no need to render this element
|