@vpmedia/phaser 1.112.0 → 1.113.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/dist/index.js +1261 -1314
- package/dist/index.js.map +1 -1
- package/dist/phaser/core/animation.d.ts +14 -10
- package/dist/phaser/core/animation.d.ts.map +1 -1
- package/dist/phaser/core/animation_manager.d.ts +10 -8
- package/dist/phaser/core/animation_manager.d.ts.map +1 -1
- package/dist/phaser/core/animation_parser.d.ts +5 -4
- package/dist/phaser/core/animation_parser.d.ts.map +1 -1
- package/dist/phaser/core/array_set.d.ts.map +1 -1
- package/dist/phaser/core/cache.d.ts +4 -3
- package/dist/phaser/core/cache.d.ts.map +1 -1
- package/dist/phaser/core/const.d.ts.map +1 -1
- package/dist/phaser/core/device.d.ts.map +1 -1
- package/dist/phaser/core/device_util.d.ts.map +1 -1
- package/dist/phaser/core/dom.d.ts +3 -2
- package/dist/phaser/core/dom.d.ts.map +1 -1
- package/dist/phaser/core/event_manager.d.ts.map +1 -1
- package/dist/phaser/core/factory.d.ts +1 -1
- package/dist/phaser/core/factory.d.ts.map +1 -1
- package/dist/phaser/core/frame.d.ts.map +1 -1
- package/dist/phaser/core/frame_data.d.ts.map +1 -1
- package/dist/phaser/core/game.d.ts.map +1 -1
- package/dist/phaser/core/input.d.ts +8 -6
- package/dist/phaser/core/input.d.ts.map +1 -1
- package/dist/phaser/core/input_handler.d.ts +40 -30
- package/dist/phaser/core/input_handler.d.ts.map +1 -1
- package/dist/phaser/core/input_mouse.d.ts +3 -2
- package/dist/phaser/core/input_mouse.d.ts.map +1 -1
- package/dist/phaser/core/input_mspointer.d.ts +3 -2
- package/dist/phaser/core/input_mspointer.d.ts.map +1 -1
- package/dist/phaser/core/input_pointer.d.ts +6 -4
- package/dist/phaser/core/input_pointer.d.ts.map +1 -1
- package/dist/phaser/core/input_touch.d.ts +3 -2
- package/dist/phaser/core/input_touch.d.ts.map +1 -1
- package/dist/phaser/core/loader.d.ts +4 -3
- package/dist/phaser/core/loader.d.ts.map +1 -1
- package/dist/phaser/core/loader_parser.d.ts +9 -8
- package/dist/phaser/core/loader_parser.d.ts.map +1 -1
- package/dist/phaser/core/raf.d.ts +3 -2
- package/dist/phaser/core/raf.d.ts.map +1 -1
- package/dist/phaser/core/registry.d.ts +7 -0
- package/dist/phaser/core/registry.d.ts.map +1 -0
- package/dist/phaser/core/scale_manager.d.ts +1 -1
- package/dist/phaser/core/scale_manager.d.ts.map +1 -1
- package/dist/phaser/core/scene.d.ts +0 -1
- package/dist/phaser/core/scene.d.ts.map +1 -1
- package/dist/phaser/core/scene_manager.d.ts +1 -1
- package/dist/phaser/core/scene_manager.d.ts.map +1 -1
- package/dist/phaser/core/signal.d.ts +0 -1
- package/dist/phaser/core/signal.d.ts.map +1 -1
- package/dist/phaser/core/signal_binding.d.ts +4 -3
- package/dist/phaser/core/signal_binding.d.ts.map +1 -1
- package/dist/phaser/core/sound.d.ts +6 -4
- package/dist/phaser/core/sound.d.ts.map +1 -1
- package/dist/phaser/core/sound_manager.d.ts +3 -2
- package/dist/phaser/core/sound_manager.d.ts.map +1 -1
- package/dist/phaser/core/sound_sprite.d.ts +5 -4
- package/dist/phaser/core/sound_sprite.d.ts.map +1 -1
- package/dist/phaser/core/stage.d.ts +3 -2
- package/dist/phaser/core/stage.d.ts.map +1 -1
- package/dist/phaser/core/time.d.ts +1 -1
- package/dist/phaser/core/time.d.ts.map +1 -1
- package/dist/phaser/core/timer.d.ts +1 -1
- package/dist/phaser/core/timer.d.ts.map +1 -1
- package/dist/phaser/core/timer_event.d.ts.map +1 -1
- package/dist/phaser/core/tween.d.ts +10 -7
- package/dist/phaser/core/tween.d.ts.map +1 -1
- package/dist/phaser/core/tween_data.d.ts +3 -2
- package/dist/phaser/core/tween_data.d.ts.map +1 -1
- package/dist/phaser/core/tween_easing.d.ts.map +1 -1
- package/dist/phaser/core/tween_manager.d.ts +3 -2
- package/dist/phaser/core/tween_manager.d.ts.map +1 -1
- package/dist/phaser/core/world.d.ts +3 -2
- package/dist/phaser/core/world.d.ts.map +1 -1
- package/dist/phaser/display/bitmap_text.d.ts +3 -2
- package/dist/phaser/display/bitmap_text.d.ts.map +1 -1
- package/dist/phaser/display/button.d.ts +3 -2
- package/dist/phaser/display/button.d.ts.map +1 -1
- package/dist/phaser/display/canvas/buffer.d.ts.map +1 -1
- package/dist/phaser/display/canvas/graphics.d.ts +7 -6
- package/dist/phaser/display/canvas/graphics.d.ts.map +1 -1
- package/dist/phaser/display/canvas/pool.d.ts +2 -2
- package/dist/phaser/display/canvas/pool.d.ts.map +1 -1
- package/dist/phaser/display/canvas/renderer.d.ts +10 -8
- package/dist/phaser/display/canvas/renderer.d.ts.map +1 -1
- package/dist/phaser/display/canvas/tinter.d.ts +3 -2
- package/dist/phaser/display/canvas/tinter.d.ts.map +1 -1
- package/dist/phaser/display/canvas/util.d.ts +2 -2
- package/dist/phaser/display/canvas/util.d.ts.map +1 -1
- package/dist/phaser/display/display_object.d.ts +14 -12
- package/dist/phaser/display/display_object.d.ts.map +1 -1
- package/dist/phaser/display/graphics.d.ts +8 -5
- package/dist/phaser/display/graphics.d.ts.map +1 -1
- package/dist/phaser/display/graphics_data.d.ts.map +1 -1
- package/dist/phaser/display/graphics_data_util.d.ts.map +1 -1
- package/dist/phaser/display/group.d.ts +4 -3
- package/dist/phaser/display/group.d.ts.map +1 -1
- package/dist/phaser/display/image.d.ts +13 -10
- package/dist/phaser/display/image.d.ts.map +1 -1
- package/dist/phaser/display/sprite_batch.d.ts +3 -2
- package/dist/phaser/display/sprite_batch.d.ts.map +1 -1
- package/dist/phaser/display/sprite_util.d.ts +18 -15
- package/dist/phaser/display/sprite_util.d.ts.map +1 -1
- package/dist/phaser/display/text.d.ts +11 -9
- package/dist/phaser/display/text.d.ts.map +1 -1
- package/dist/phaser/display/webgl/abstract_filter.d.ts.map +1 -1
- package/dist/phaser/display/webgl/base_texture.d.ts.map +1 -1
- package/dist/phaser/display/webgl/blend_manager.d.ts +0 -1
- package/dist/phaser/display/webgl/blend_manager.d.ts.map +1 -1
- package/dist/phaser/display/webgl/earcut.d.ts +1 -1
- package/dist/phaser/display/webgl/earcut.d.ts.map +1 -1
- package/dist/phaser/display/webgl/earcut_node.d.ts.map +1 -1
- package/dist/phaser/display/webgl/fast_sprite_batch.d.ts +4 -3
- package/dist/phaser/display/webgl/fast_sprite_batch.d.ts.map +1 -1
- package/dist/phaser/display/webgl/filter_manager.d.ts +2 -1
- package/dist/phaser/display/webgl/filter_manager.d.ts.map +1 -1
- package/dist/phaser/display/webgl/filter_texture.d.ts +2 -1
- package/dist/phaser/display/webgl/filter_texture.d.ts.map +1 -1
- package/dist/phaser/display/webgl/graphics.d.ts +7 -6
- package/dist/phaser/display/webgl/graphics.d.ts.map +1 -1
- package/dist/phaser/display/webgl/graphics_data.d.ts +2 -1
- package/dist/phaser/display/webgl/graphics_data.d.ts.map +1 -1
- package/dist/phaser/display/webgl/render_texture.d.ts +4 -2
- package/dist/phaser/display/webgl/render_texture.d.ts.map +1 -1
- package/dist/phaser/display/webgl/renderer.d.ts +16 -11
- package/dist/phaser/display/webgl/renderer.d.ts.map +1 -1
- package/dist/phaser/display/webgl/shader/complex.d.ts +16 -6
- package/dist/phaser/display/webgl/shader/complex.d.ts.map +1 -1
- package/dist/phaser/display/webgl/shader/fast.d.ts +19 -7
- package/dist/phaser/display/webgl/shader/fast.d.ts.map +1 -1
- package/dist/phaser/display/webgl/shader/normal.d.ts +33 -12
- package/dist/phaser/display/webgl/shader/normal.d.ts.map +1 -1
- package/dist/phaser/display/webgl/shader/primitive.d.ts +15 -6
- package/dist/phaser/display/webgl/shader/primitive.d.ts.map +1 -1
- package/dist/phaser/display/webgl/shader/strip.d.ts +15 -6
- package/dist/phaser/display/webgl/shader/strip.d.ts.map +1 -1
- package/dist/phaser/display/webgl/shader_manager.d.ts +16 -11
- package/dist/phaser/display/webgl/shader_manager.d.ts.map +1 -1
- package/dist/phaser/display/webgl/sprite_batch.d.ts +29 -20
- package/dist/phaser/display/webgl/sprite_batch.d.ts.map +1 -1
- package/dist/phaser/display/webgl/stencil_manager.d.ts +12 -10
- package/dist/phaser/display/webgl/stencil_manager.d.ts.map +1 -1
- package/dist/phaser/display/webgl/texture.d.ts +3 -2
- package/dist/phaser/display/webgl/texture.d.ts.map +1 -1
- package/dist/phaser/display/webgl/texture_util.d.ts.map +1 -1
- package/dist/phaser/display/webgl/util.d.ts.map +1 -1
- package/dist/phaser/geom/circle.d.ts +4 -1
- package/dist/phaser/geom/circle.d.ts.map +1 -1
- package/dist/phaser/geom/ellipse.d.ts.map +1 -1
- package/dist/phaser/geom/line.d.ts +1 -1
- package/dist/phaser/geom/line.d.ts.map +1 -1
- package/dist/phaser/geom/matrix.d.ts.map +1 -1
- package/dist/phaser/geom/point.d.ts.map +1 -1
- package/dist/phaser/geom/polygon.d.ts.map +1 -1
- package/dist/phaser/geom/rectangle.d.ts.map +1 -1
- package/dist/phaser/geom/rounded_rectangle.d.ts.map +1 -1
- package/dist/phaser/geom/util/circle.d.ts.map +1 -1
- package/dist/phaser/geom/util/ellipse.d.ts +3 -2
- package/dist/phaser/geom/util/ellipse.d.ts.map +1 -1
- package/dist/phaser/geom/util/line.d.ts.map +1 -1
- package/dist/phaser/geom/util/matrix.d.ts +2 -2
- package/dist/phaser/geom/util/matrix.d.ts.map +1 -1
- package/dist/phaser/geom/util/point.d.ts.map +1 -1
- package/dist/phaser/geom/util/rectangle.d.ts +1 -1
- package/dist/phaser/geom/util/rectangle.d.ts.map +1 -1
- package/dist/phaser/util/math.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/phaser/core/animation.ts +64 -60
- package/src/phaser/core/animation_manager.ts +50 -53
- package/src/phaser/core/animation_parser.ts +9 -9
- package/src/phaser/core/array_set.ts +16 -17
- package/src/phaser/core/cache.ts +92 -93
- package/src/phaser/core/const.ts +1 -1
- package/src/phaser/core/device.ts +24 -29
- package/src/phaser/core/device_util.ts +22 -26
- package/src/phaser/core/dom.ts +54 -65
- package/src/phaser/core/event_manager.ts +64 -94
- package/src/phaser/core/factory.ts +14 -14
- package/src/phaser/core/frame.ts +28 -28
- package/src/phaser/core/frame_data.test.ts +100 -0
- package/src/phaser/core/frame_data.ts +24 -24
- package/src/phaser/core/frame_util.ts +2 -2
- package/src/phaser/core/game.ts +47 -48
- package/src/phaser/core/input.ts +104 -110
- package/src/phaser/core/input_handler.test.ts +113 -0
- package/src/phaser/core/input_handler.ts +199 -218
- package/src/phaser/core/input_mouse.ts +71 -54
- package/src/phaser/core/input_mspointer.ts +52 -39
- package/src/phaser/core/input_pointer.ts +81 -80
- package/src/phaser/core/input_touch.ts +49 -36
- package/src/phaser/core/loader.ts +173 -152
- package/src/phaser/core/loader_parser.ts +39 -57
- package/src/phaser/core/raf.ts +8 -7
- package/src/phaser/core/registry.test.ts +31 -0
- package/src/phaser/core/registry.ts +9 -0
- package/src/phaser/core/scale_manager.ts +156 -152
- package/src/phaser/core/scene.ts +9 -13
- package/src/phaser/core/scene_manager.ts +47 -47
- package/src/phaser/core/signal.test.ts +4 -4
- package/src/phaser/core/signal.ts +41 -52
- package/src/phaser/core/signal_binding.ts +26 -25
- package/src/phaser/core/signal_dispatch.test.ts +180 -0
- package/src/phaser/core/sound.ts +75 -83
- package/src/phaser/core/sound_manager.ts +52 -51
- package/src/phaser/core/sound_sprite.ts +17 -16
- package/src/phaser/core/stage.ts +25 -24
- package/src/phaser/core/time.ts +52 -52
- package/src/phaser/core/timer.test.ts +187 -0
- package/src/phaser/core/timer.ts +82 -69
- package/src/phaser/core/timer_event.ts +10 -10
- package/src/phaser/core/tween.ts +90 -93
- package/src/phaser/core/tween_data.ts +45 -51
- package/src/phaser/core/tween_easing.test.ts +106 -0
- package/src/phaser/core/tween_easing.ts +151 -123
- package/src/phaser/core/tween_manager.ts +19 -18
- package/src/phaser/core/world.ts +4 -3
- package/src/phaser/display/bitmap_text.ts +56 -64
- package/src/phaser/display/button.ts +33 -32
- package/src/phaser/display/canvas/buffer.ts +8 -8
- package/src/phaser/display/canvas/graphics.ts +36 -37
- package/src/phaser/display/canvas/masker.ts +2 -2
- package/src/phaser/display/canvas/pool.test.ts +106 -0
- package/src/phaser/display/canvas/pool.ts +25 -27
- package/src/phaser/display/canvas/renderer.ts +32 -31
- package/src/phaser/display/canvas/tinter.ts +25 -25
- package/src/phaser/display/canvas/util.ts +7 -10
- package/src/phaser/display/display_object.ts +114 -118
- package/src/phaser/display/graphics.ts +121 -119
- package/src/phaser/display/graphics_data.ts +12 -12
- package/src/phaser/display/graphics_data_util.ts +2 -3
- package/src/phaser/display/group.ts +50 -57
- package/src/phaser/display/image.ts +55 -52
- package/src/phaser/display/sprite_batch.ts +3 -2
- package/src/phaser/display/sprite_util.ts +48 -54
- package/src/phaser/display/text.ts +199 -204
- package/src/phaser/display/webgl/abstract_filter.ts +9 -9
- package/src/phaser/display/webgl/base_texture.ts +21 -24
- package/src/phaser/display/webgl/blend_manager.ts +6 -10
- package/src/phaser/display/webgl/earcut.ts +73 -37
- package/src/phaser/display/webgl/earcut_node.ts +10 -10
- package/src/phaser/display/webgl/fast_sprite_batch.ts +34 -34
- package/src/phaser/display/webgl/filter_manager.ts +13 -12
- package/src/phaser/display/webgl/filter_texture.ts +14 -13
- package/src/phaser/display/webgl/graphics.ts +51 -57
- package/src/phaser/display/webgl/graphics_data.ts +15 -14
- package/src/phaser/display/webgl/mask_manager.ts +2 -2
- package/src/phaser/display/webgl/render_texture.ts +26 -25
- package/src/phaser/display/webgl/renderer.ts +57 -62
- package/src/phaser/display/webgl/shader/complex.ts +28 -12
- package/src/phaser/display/webgl/shader/fast.ts +30 -12
- package/src/phaser/display/webgl/shader/normal.ts +70 -57
- package/src/phaser/display/webgl/shader/primitive.ts +26 -11
- package/src/phaser/display/webgl/shader/shader.test.ts +148 -0
- package/src/phaser/display/webgl/shader/strip.ts +27 -12
- package/src/phaser/display/webgl/shader_manager.test.ts +124 -0
- package/src/phaser/display/webgl/shader_manager.ts +26 -34
- package/src/phaser/display/webgl/sprite_batch.ts +67 -61
- package/src/phaser/display/webgl/stencil_manager.ts +23 -34
- package/src/phaser/display/webgl/texture.ts +43 -50
- package/src/phaser/display/webgl/texture_util.ts +2 -3
- package/src/phaser/display/webgl/util.ts +26 -25
- package/src/phaser/geom/circle.test.ts +2 -3
- package/src/phaser/geom/circle.ts +36 -36
- package/src/phaser/geom/ellipse.test.ts +73 -71
- package/src/phaser/geom/ellipse.ts +14 -14
- package/src/phaser/geom/line.test.ts +5 -5
- package/src/phaser/geom/line.ts +35 -35
- package/src/phaser/geom/matrix.test.ts +1 -1
- package/src/phaser/geom/matrix.ts +27 -27
- package/src/phaser/geom/point.test.ts +1 -2
- package/src/phaser/geom/point.ts +35 -35
- package/src/phaser/geom/polygon.test.ts +82 -0
- package/src/phaser/geom/polygon.ts +16 -16
- package/src/phaser/geom/rectangle.test.ts +14 -14
- package/src/phaser/geom/rectangle.ts +83 -75
- package/src/phaser/geom/rounded_rectangle.test.ts +1 -7
- package/src/phaser/geom/rounded_rectangle.ts +9 -9
- package/src/phaser/geom/util/circle.test.ts +25 -23
- package/src/phaser/geom/util/circle.ts +9 -18
- package/src/phaser/geom/util/ellipse.test.ts +7 -5
- package/src/phaser/geom/util/ellipse.ts +3 -2
- package/src/phaser/geom/util/line.test.ts +10 -8
- package/src/phaser/geom/util/line.ts +6 -16
- package/src/phaser/geom/util/matrix.test.ts +20 -18
- package/src/phaser/geom/util/matrix.ts +8 -15
- package/src/phaser/geom/util/point.test.ts +8 -6
- package/src/phaser/geom/util/point.ts +24 -28
- package/src/phaser/geom/util/polygon.test.ts +12 -10
- package/src/phaser/geom/util/polygon.ts +2 -2
- package/src/phaser/geom/util/rectangle.test.ts +10 -8
- package/src/phaser/geom/util/rectangle.ts +18 -37
- package/src/phaser/geom/util/rounded_rectangle.test.ts +11 -9
- package/src/phaser/geom/util/rounded_rectangle.ts +1 -1
- package/src/phaser/util/math.test.ts +11 -11
- package/src/phaser/util/math.ts +29 -46
|
@@ -1,52 +1,56 @@
|
|
|
1
1
|
import { Signal } from './signal.js';
|
|
2
|
+
import type { Game } from './game.js';
|
|
3
|
+
import type { Image } from '../display/image.js';
|
|
4
|
+
import type { FrameData } from './frame_data.js';
|
|
5
|
+
import type { Frame } from './frame.js';
|
|
2
6
|
|
|
3
7
|
export class Animation {
|
|
4
|
-
game!:
|
|
5
|
-
_parent!:
|
|
6
|
-
_frameData!:
|
|
7
|
-
name!: string;
|
|
8
|
-
_frames!: any;
|
|
9
|
-
delay!: number;
|
|
10
|
-
loop!: boolean;
|
|
11
|
-
loopCount!: number;
|
|
12
|
-
isFinished!: boolean;
|
|
13
|
-
isPlaying!: boolean;
|
|
14
|
-
isPaused!: boolean;
|
|
15
|
-
_pauseStartTime!: number;
|
|
16
|
-
_frameIndex!: number;
|
|
17
|
-
_frameDiff!: number;
|
|
18
|
-
_frameSkip!: number;
|
|
19
|
-
currentFrame!:
|
|
20
|
-
onStart!: Signal;
|
|
21
|
-
onUpdate!: Signal | null;
|
|
22
|
-
onComplete!: Signal;
|
|
23
|
-
onLoop!: Signal;
|
|
24
|
-
isReversed!: boolean;
|
|
25
|
-
_timeLastFrame!: number;
|
|
26
|
-
_timeNextFrame!: number;
|
|
8
|
+
public game!: Game;
|
|
9
|
+
public _parent!: Image;
|
|
10
|
+
public _frameData!: FrameData;
|
|
11
|
+
public name!: string;
|
|
12
|
+
public _frames!: any;
|
|
13
|
+
public delay!: number;
|
|
14
|
+
public loop!: boolean;
|
|
15
|
+
public loopCount!: number;
|
|
16
|
+
public isFinished!: boolean;
|
|
17
|
+
public isPlaying!: boolean;
|
|
18
|
+
public isPaused!: boolean;
|
|
19
|
+
public _pauseStartTime!: number;
|
|
20
|
+
public _frameIndex!: number;
|
|
21
|
+
public _frameDiff!: number;
|
|
22
|
+
public _frameSkip!: number;
|
|
23
|
+
public currentFrame!: Frame | null;
|
|
24
|
+
public onStart!: Signal;
|
|
25
|
+
public onUpdate!: Signal | null;
|
|
26
|
+
public onComplete!: Signal;
|
|
27
|
+
public onLoop!: Signal;
|
|
28
|
+
public isReversed!: boolean;
|
|
29
|
+
public _timeLastFrame!: number;
|
|
30
|
+
public _timeNextFrame!: number;
|
|
27
31
|
/**
|
|
28
32
|
* Creates a new Animation instance.
|
|
29
|
-
* @param {
|
|
30
|
-
* @param {
|
|
33
|
+
* @param {Game} game - The game instance this animation belongs to.
|
|
34
|
+
* @param {Image} parent - The Image object that owns this animation.
|
|
31
35
|
* @param {string} name - The unique name of this animation.
|
|
32
|
-
* @param {
|
|
36
|
+
* @param {FrameData} frameData - The FrameData object that contains the frames for this animation.
|
|
33
37
|
* @param {string[]|number[]} frames - An array of frame identifiers (names or indices) to use in this animation.
|
|
34
38
|
* @param {number} frameRate - The frame rate at which this animation should play (frames per second).
|
|
35
39
|
* @param {boolean} loop - Whether the animation should loop when it completes.
|
|
36
40
|
*/
|
|
37
|
-
constructor(
|
|
38
|
-
game:
|
|
39
|
-
parent:
|
|
41
|
+
public constructor(
|
|
42
|
+
game: Game,
|
|
43
|
+
parent: Image,
|
|
40
44
|
name: string,
|
|
41
|
-
frameData:
|
|
45
|
+
frameData: FrameData,
|
|
42
46
|
frames: string[] | number[],
|
|
43
47
|
frameRate: number,
|
|
44
|
-
loop
|
|
48
|
+
loop = false
|
|
45
49
|
) {
|
|
46
|
-
/** @type {
|
|
50
|
+
/** @type {Game} */
|
|
47
51
|
this.game = game;
|
|
48
52
|
this._parent = parent;
|
|
49
|
-
/** @type {
|
|
53
|
+
/** @type {FrameData} */
|
|
50
54
|
this._frameData = frameData;
|
|
51
55
|
/** @type {string} */
|
|
52
56
|
this.name = name;
|
|
@@ -94,7 +98,7 @@ export class Animation {
|
|
|
94
98
|
* @param {boolean} loop - Whether to loop this animation (if null, uses the original loop setting).
|
|
95
99
|
* @returns {Animation} This Animation instance for chaining.
|
|
96
100
|
*/
|
|
97
|
-
play(frameRate: number | null = null, loop: boolean | null = null) {
|
|
101
|
+
public play(frameRate: number | null = null, loop: boolean | null = null) {
|
|
98
102
|
if (typeof frameRate === 'number') {
|
|
99
103
|
// If they set a new frame rate then use it, otherwise use the one set on creation
|
|
100
104
|
this.delay = 1000 / frameRate;
|
|
@@ -121,7 +125,7 @@ export class Animation {
|
|
|
121
125
|
/**
|
|
122
126
|
* Restarts this animation from the beginning.
|
|
123
127
|
*/
|
|
124
|
-
restart() {
|
|
128
|
+
public restart() {
|
|
125
129
|
this.isPlaying = true;
|
|
126
130
|
this.isFinished = false;
|
|
127
131
|
this.paused = false;
|
|
@@ -140,7 +144,7 @@ export class Animation {
|
|
|
140
144
|
* Reverses the direction of this animation.
|
|
141
145
|
* @returns {Animation} This Animation instance for chaining.
|
|
142
146
|
*/
|
|
143
|
-
reverse() {
|
|
147
|
+
public reverse() {
|
|
144
148
|
this.reversed = !this.reversed;
|
|
145
149
|
return this;
|
|
146
150
|
}
|
|
@@ -149,7 +153,7 @@ export class Animation {
|
|
|
149
153
|
* Reverses the animation direction once, then returns to normal direction.
|
|
150
154
|
* @returns {Animation} This Animation instance for chaining.
|
|
151
155
|
*/
|
|
152
|
-
reverseOnce() {
|
|
156
|
+
public reverseOnce() {
|
|
153
157
|
this.onComplete.addOnce(this.reverse, this);
|
|
154
158
|
this.reverse();
|
|
155
159
|
return this;
|
|
@@ -160,7 +164,7 @@ export class Animation {
|
|
|
160
164
|
* @param {string|number} frameId - The identifier (name or index) of the frame to set.
|
|
161
165
|
* @param {boolean} useLocalFrameIndex - If true, treats frameId as an index into the local frames array.
|
|
162
166
|
*/
|
|
163
|
-
setFrame(frameId: string | number, useLocalFrameIndex
|
|
167
|
+
public setFrame(frameId: string | number, useLocalFrameIndex = false) {
|
|
164
168
|
let frameIndex;
|
|
165
169
|
// Find the index to the desired frame.
|
|
166
170
|
if (typeof frameId === 'string') {
|
|
@@ -194,7 +198,7 @@ export class Animation {
|
|
|
194
198
|
* @param {boolean} resetFrame - If true, resets to the first frame.
|
|
195
199
|
* @param {boolean} dispatchComplete - If true, dispatches the onComplete signal.
|
|
196
200
|
*/
|
|
197
|
-
stop(resetFrame
|
|
201
|
+
public stop(resetFrame = false, dispatchComplete = false) {
|
|
198
202
|
this.isPlaying = false;
|
|
199
203
|
this.isFinished = true;
|
|
200
204
|
this.paused = false;
|
|
@@ -213,7 +217,7 @@ export class Animation {
|
|
|
213
217
|
/**
|
|
214
218
|
* Called when the game is paused.
|
|
215
219
|
*/
|
|
216
|
-
onPause() {
|
|
220
|
+
public onPause() {
|
|
217
221
|
if (this.isPlaying) {
|
|
218
222
|
this._frameDiff = this._timeNextFrame - this.game.time.time;
|
|
219
223
|
}
|
|
@@ -222,7 +226,7 @@ export class Animation {
|
|
|
222
226
|
/**
|
|
223
227
|
* Called when the game is resumed.
|
|
224
228
|
*/
|
|
225
|
-
onResume() {
|
|
229
|
+
public onResume() {
|
|
226
230
|
if (this.isPlaying) {
|
|
227
231
|
this._timeNextFrame = this.game.time.time + this._frameDiff;
|
|
228
232
|
}
|
|
@@ -232,7 +236,7 @@ export class Animation {
|
|
|
232
236
|
* Updates this animation.
|
|
233
237
|
* @returns {boolean} True if the animation was updated, false otherwise.
|
|
234
238
|
*/
|
|
235
|
-
update() {
|
|
239
|
+
public update() {
|
|
236
240
|
if (this.isPaused) {
|
|
237
241
|
return false;
|
|
238
242
|
}
|
|
@@ -293,7 +297,7 @@ export class Animation {
|
|
|
293
297
|
* @param {boolean} fromPlay - Whether this call is from play().
|
|
294
298
|
* @returns {boolean} True if the frame was updated, false otherwise.
|
|
295
299
|
*/
|
|
296
|
-
updateCurrentFrame(signalUpdate: boolean, fromPlay
|
|
300
|
+
public updateCurrentFrame(signalUpdate: boolean, fromPlay = false) {
|
|
297
301
|
if (!this._frameData || !this.currentFrame) {
|
|
298
302
|
// The animation is already destroyed, probably from a callback
|
|
299
303
|
return false;
|
|
@@ -316,7 +320,7 @@ export class Animation {
|
|
|
316
320
|
* Advances the animation to the next frame(s).
|
|
317
321
|
* @param {number} quantity - The number of frames to advance by.
|
|
318
322
|
*/
|
|
319
|
-
next(quantity
|
|
323
|
+
public next(quantity = 1) {
|
|
320
324
|
let frame = this._frameIndex + quantity;
|
|
321
325
|
if (frame >= this._frames.length) {
|
|
322
326
|
if (this.loop) {
|
|
@@ -335,7 +339,7 @@ export class Animation {
|
|
|
335
339
|
* Moves the animation to the previous frame(s).
|
|
336
340
|
* @param {number} quantity - The number of frames to move back by.
|
|
337
341
|
*/
|
|
338
|
-
previous(quantity
|
|
342
|
+
public previous(quantity = 1) {
|
|
339
343
|
let frame = this._frameIndex - quantity;
|
|
340
344
|
if (frame < 0) {
|
|
341
345
|
if (this.loop) {
|
|
@@ -352,9 +356,9 @@ export class Animation {
|
|
|
352
356
|
|
|
353
357
|
/**
|
|
354
358
|
* Updates the frame data used by this animation.
|
|
355
|
-
* @param {
|
|
359
|
+
* @param {FrameData} frameData - The new FrameData object to use.
|
|
356
360
|
*/
|
|
357
|
-
updateFrameData(frameData:
|
|
361
|
+
public updateFrameData(frameData: FrameData) {
|
|
358
362
|
this._frameData = frameData;
|
|
359
363
|
this.currentFrame = this._frameData
|
|
360
364
|
? this._frameData.getFrame(this._frames[this._frameIndex % this._frames.length])
|
|
@@ -364,7 +368,7 @@ export class Animation {
|
|
|
364
368
|
/**
|
|
365
369
|
* Destroys this animation and cleans up resources.
|
|
366
370
|
*/
|
|
367
|
-
destroy() {
|
|
371
|
+
public destroy() {
|
|
368
372
|
if (!this._frameData) {
|
|
369
373
|
// Already destroyed
|
|
370
374
|
return;
|
|
@@ -388,7 +392,7 @@ export class Animation {
|
|
|
388
392
|
/**
|
|
389
393
|
* Completes this animation, setting it to the final frame.
|
|
390
394
|
*/
|
|
391
|
-
complete() {
|
|
395
|
+
public complete() {
|
|
392
396
|
this._frameIndex = this._frames.length - 1;
|
|
393
397
|
this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]);
|
|
394
398
|
this.isPlaying = false;
|
|
@@ -402,7 +406,7 @@ export class Animation {
|
|
|
402
406
|
* Gets whether this animation is currently paused.
|
|
403
407
|
* @returns {boolean} True if the animation is paused, false otherwise.
|
|
404
408
|
*/
|
|
405
|
-
get paused() {
|
|
409
|
+
public get paused() {
|
|
406
410
|
return this.isPaused;
|
|
407
411
|
}
|
|
408
412
|
|
|
@@ -410,7 +414,7 @@ export class Animation {
|
|
|
410
414
|
* Sets whether this animation is currently paused.
|
|
411
415
|
* @param {boolean} value - True to pause the animation, false to resume it.
|
|
412
416
|
*/
|
|
413
|
-
set paused(value: boolean) {
|
|
417
|
+
public set paused(value: boolean) {
|
|
414
418
|
this.isPaused = value;
|
|
415
419
|
if (value) {
|
|
416
420
|
this._pauseStartTime = this.game.time.time;
|
|
@@ -423,7 +427,7 @@ export class Animation {
|
|
|
423
427
|
* Gets whether this animation is currently reversed.
|
|
424
428
|
* @returns {boolean} True if the animation is reversed, false otherwise.
|
|
425
429
|
*/
|
|
426
|
-
get reversed() {
|
|
430
|
+
public get reversed() {
|
|
427
431
|
return this.isReversed;
|
|
428
432
|
}
|
|
429
433
|
|
|
@@ -431,7 +435,7 @@ export class Animation {
|
|
|
431
435
|
* Sets whether this animation is currently reversed.
|
|
432
436
|
* @param {boolean} value - True to reverse the animation, false to normal direction.
|
|
433
437
|
*/
|
|
434
|
-
set reversed(value: boolean) {
|
|
438
|
+
public set reversed(value: boolean) {
|
|
435
439
|
this.isReversed = value;
|
|
436
440
|
}
|
|
437
441
|
|
|
@@ -439,7 +443,7 @@ export class Animation {
|
|
|
439
443
|
* Gets the total number of frames in this animation.
|
|
440
444
|
* @returns {number} The total number of frames.
|
|
441
445
|
*/
|
|
442
|
-
get frameTotal() {
|
|
446
|
+
public get frameTotal() {
|
|
443
447
|
return this._frames.length;
|
|
444
448
|
}
|
|
445
449
|
|
|
@@ -447,7 +451,7 @@ export class Animation {
|
|
|
447
451
|
* Gets the current frame index.
|
|
448
452
|
* @returns {number} The current frame index.
|
|
449
453
|
*/
|
|
450
|
-
get frame() {
|
|
454
|
+
public get frame() {
|
|
451
455
|
if (this.currentFrame !== null) {
|
|
452
456
|
return this.currentFrame.index;
|
|
453
457
|
}
|
|
@@ -458,7 +462,7 @@ export class Animation {
|
|
|
458
462
|
* Sets the current frame index.
|
|
459
463
|
* @param {number} value - The new frame index to set.
|
|
460
464
|
*/
|
|
461
|
-
set frame(value: number) {
|
|
465
|
+
public set frame(value: number) {
|
|
462
466
|
this.currentFrame = this._frameData.getFrame(this._frames[value]);
|
|
463
467
|
if (this.currentFrame !== null) {
|
|
464
468
|
this._frameIndex = value;
|
|
@@ -473,7 +477,7 @@ export class Animation {
|
|
|
473
477
|
* Gets the current animation speed (frame rate).
|
|
474
478
|
* @returns {number} The frame rate in frames per second.
|
|
475
479
|
*/
|
|
476
|
-
get speed() {
|
|
480
|
+
public get speed() {
|
|
477
481
|
return 1000 / this.delay;
|
|
478
482
|
}
|
|
479
483
|
|
|
@@ -481,7 +485,7 @@ export class Animation {
|
|
|
481
485
|
* Sets the animation speed (frame rate).
|
|
482
486
|
* @param {number} value - The new frame rate in frames per second.
|
|
483
487
|
*/
|
|
484
|
-
set speed(value: number) {
|
|
488
|
+
public set speed(value: number) {
|
|
485
489
|
if (value > 0) {
|
|
486
490
|
this.delay = 1000 / value;
|
|
487
491
|
}
|
|
@@ -491,7 +495,7 @@ export class Animation {
|
|
|
491
495
|
* Gets whether the update signal is enabled.
|
|
492
496
|
* @returns {boolean} True if the update signal is enabled, false otherwise.
|
|
493
497
|
*/
|
|
494
|
-
get enableUpdate() {
|
|
498
|
+
public get enableUpdate() {
|
|
495
499
|
return this.onUpdate !== null;
|
|
496
500
|
}
|
|
497
501
|
|
|
@@ -499,7 +503,7 @@ export class Animation {
|
|
|
499
503
|
* Sets whether the update signal is enabled.
|
|
500
504
|
* @param {boolean} value - True to enable the update signal, false to disable it.
|
|
501
505
|
*/
|
|
502
|
-
set enableUpdate(value: boolean) {
|
|
506
|
+
public set enableUpdate(value: boolean) {
|
|
503
507
|
if (value && this.onUpdate === null) {
|
|
504
508
|
this.onUpdate = new Signal();
|
|
505
509
|
} else if (!value && this.onUpdate !== null) {
|
|
@@ -1,22 +1,24 @@
|
|
|
1
1
|
import { Animation } from './animation.js';
|
|
2
2
|
import { ENGINE_ERROR_CANNOT_SET_FRAME, ENGINE_ERROR_CANNOT_SET_FRAME_NAME } from './error_code.js';
|
|
3
|
+
import type { Image } from '../display/image.js';
|
|
4
|
+
import type { FrameData } from './frame_data.js';
|
|
3
5
|
|
|
4
6
|
export class AnimationManager {
|
|
5
|
-
sprite!: any;
|
|
6
|
-
game!: any;
|
|
7
|
-
currentFrame!: any;
|
|
8
|
-
currentAnim!: any;
|
|
9
|
-
updateIfVisible!: boolean;
|
|
10
|
-
isLoaded!: boolean;
|
|
11
|
-
_frameData!: any;
|
|
12
|
-
_anims!: Record<string, Animation>;
|
|
13
|
-
_outputFrames!: number[];
|
|
14
|
-
_frameIndex!: number;
|
|
7
|
+
public sprite!: any;
|
|
8
|
+
public game!: any;
|
|
9
|
+
public currentFrame!: any;
|
|
10
|
+
public currentAnim!: any;
|
|
11
|
+
public updateIfVisible!: boolean;
|
|
12
|
+
public isLoaded!: boolean;
|
|
13
|
+
public _frameData!: any;
|
|
14
|
+
public _anims!: Record<string, Animation>;
|
|
15
|
+
public _outputFrames!: number[];
|
|
16
|
+
public _frameIndex!: number;
|
|
15
17
|
/**
|
|
16
18
|
* Creates a new AnimationManager instance.
|
|
17
|
-
* @param {
|
|
19
|
+
* @param {Image} sprite - Reference to the parent Sprite.
|
|
18
20
|
*/
|
|
19
|
-
constructor(sprite:
|
|
21
|
+
public constructor(sprite: Image) {
|
|
20
22
|
this.sprite = sprite;
|
|
21
23
|
this.game = sprite.game;
|
|
22
24
|
this.currentFrame = null;
|
|
@@ -32,10 +34,9 @@ export class AnimationManager {
|
|
|
32
34
|
/**
|
|
33
35
|
* Destroys the AnimationManager and cleans up resources.
|
|
34
36
|
*/
|
|
35
|
-
destroy() {
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
this._anims[keys[i]].destroy();
|
|
37
|
+
public destroy() {
|
|
38
|
+
for (const anim of Object.values(this._anims)) {
|
|
39
|
+
anim.destroy();
|
|
39
40
|
}
|
|
40
41
|
this._anims = {};
|
|
41
42
|
this._outputFrames = [];
|
|
@@ -48,20 +49,18 @@ export class AnimationManager {
|
|
|
48
49
|
|
|
49
50
|
/**
|
|
50
51
|
* Loads frame data into the AnimationManager.
|
|
51
|
-
* @param {
|
|
52
|
+
* @param {FrameData} frameData - The FrameData to load.
|
|
52
53
|
* @param {string|number} frame - The frame index or name to set as current.
|
|
53
54
|
* @returns {boolean} True if the frame data was loaded successfully, false otherwise.
|
|
54
55
|
*/
|
|
55
|
-
loadFrameData(frameData:
|
|
56
|
+
public loadFrameData(frameData: FrameData, frame: string | number) {
|
|
56
57
|
if (!frameData) {
|
|
57
58
|
return false;
|
|
58
59
|
}
|
|
59
60
|
if (this.isLoaded) {
|
|
60
61
|
// We need to update the frameData that the animations are using
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
const anim = keys[i];
|
|
64
|
-
this._anims[anim].updateFrameData(frameData);
|
|
62
|
+
for (const anim of Object.values(this._anims)) {
|
|
63
|
+
anim.updateFrameData(frameData);
|
|
65
64
|
}
|
|
66
65
|
}
|
|
67
66
|
this._frameData = frameData;
|
|
@@ -78,18 +77,16 @@ export class AnimationManager {
|
|
|
78
77
|
|
|
79
78
|
/**
|
|
80
79
|
* Copies frame data into the AnimationManager.
|
|
81
|
-
* @param {
|
|
80
|
+
* @param {FrameData} frameData - The FrameData to copy.
|
|
82
81
|
* @param {string|number} frame - The frame index or name to set as current.
|
|
83
82
|
* @returns {boolean} True if the frame data was copied successfully, false otherwise.
|
|
84
83
|
*/
|
|
85
|
-
copyFrameData(frameData:
|
|
84
|
+
public copyFrameData(frameData: FrameData, frame: string | number) {
|
|
86
85
|
this._frameData = frameData.clone();
|
|
87
86
|
if (this.isLoaded) {
|
|
88
87
|
// We need to update the frameData that the animations are using
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
const anim = keys[i];
|
|
92
|
-
this._anims[anim].updateFrameData(this._frameData);
|
|
88
|
+
for (const anim of Object.values(this._anims)) {
|
|
89
|
+
anim.updateFrameData(this._frameData);
|
|
93
90
|
}
|
|
94
91
|
}
|
|
95
92
|
if (frame === undefined || frame === null) {
|
|
@@ -112,14 +109,14 @@ export class AnimationManager {
|
|
|
112
109
|
* @param {boolean | undefined} useNumericIndex - Whether to treat frameList as numeric indices.
|
|
113
110
|
* @returns {Animation} The created Animation object.
|
|
114
111
|
*/
|
|
115
|
-
add(
|
|
112
|
+
public add(
|
|
116
113
|
name: string,
|
|
117
114
|
frameList: number[] | string[] | null | undefined,
|
|
118
|
-
frameRate
|
|
119
|
-
loop
|
|
120
|
-
useNumericIndex
|
|
115
|
+
frameRate = 60,
|
|
116
|
+
loop = false,
|
|
117
|
+
useNumericIndex?: boolean
|
|
121
118
|
) {
|
|
122
|
-
const frames = frameList
|
|
119
|
+
const frames = frameList ?? [];
|
|
123
120
|
// If they didn't set the useNumericIndex then let's at least try and guess it
|
|
124
121
|
if (useNumericIndex === undefined) {
|
|
125
122
|
if (frames && typeof frames[0] === 'number') {
|
|
@@ -152,10 +149,10 @@ export class AnimationManager {
|
|
|
152
149
|
* @param {boolean} useNumericIndex - Whether to treat frameList as numeric indices.
|
|
153
150
|
* @returns {boolean} True if all frames are valid, false otherwise.
|
|
154
151
|
*/
|
|
155
|
-
validateFrames(frames: string[] | number[], useNumericIndex
|
|
152
|
+
public validateFrames(frames: string[] | number[], useNumericIndex = false) {
|
|
156
153
|
for (let i = 0; i < frames.length; i += 1) {
|
|
157
|
-
if (useNumericIndex
|
|
158
|
-
if (frames[i] > this._frameData.total) {
|
|
154
|
+
if (useNumericIndex) {
|
|
155
|
+
if (frames[i]! > this._frameData.total) {
|
|
159
156
|
return false;
|
|
160
157
|
}
|
|
161
158
|
} else if (this._frameData.checkFrameName(frames[i]) === false) {
|
|
@@ -172,7 +169,7 @@ export class AnimationManager {
|
|
|
172
169
|
* @param {boolean} loop - Whether the animation should loop, or null to use the animation's default.
|
|
173
170
|
* @returns {Animation} The Animation object that was played, or null if not found.
|
|
174
171
|
*/
|
|
175
|
-
play(name: string, frameRate: number | null = null, loop: boolean | null = null) {
|
|
172
|
+
public play(name: string, frameRate: number | null = null, loop: boolean | null = null) {
|
|
176
173
|
if (this._anims[name]) {
|
|
177
174
|
if (this.currentAnim === this._anims[name]) {
|
|
178
175
|
if (this.currentAnim.isPlaying === false) {
|
|
@@ -197,7 +194,7 @@ export class AnimationManager {
|
|
|
197
194
|
* @param {string} name - The name of the animation to stop, or null to stop the current animation.
|
|
198
195
|
* @param {boolean} resetFrame - Whether to reset the frame to the first frame of the animation.
|
|
199
196
|
*/
|
|
200
|
-
stop(name: string | null = null, resetFrame
|
|
197
|
+
public stop(name: string | null = null, resetFrame = false) {
|
|
201
198
|
if (this.currentAnim && (typeof name !== 'string' || name === this.currentAnim.name)) {
|
|
202
199
|
this.currentAnim.stop(resetFrame);
|
|
203
200
|
}
|
|
@@ -207,7 +204,7 @@ export class AnimationManager {
|
|
|
207
204
|
* Updates the animation manager state.
|
|
208
205
|
* @returns {boolean} True if an animation was updated, false otherwise.
|
|
209
206
|
*/
|
|
210
|
-
update() {
|
|
207
|
+
public update() {
|
|
211
208
|
if (this.updateIfVisible && !this.sprite.visible) {
|
|
212
209
|
return false;
|
|
213
210
|
}
|
|
@@ -222,7 +219,7 @@ export class AnimationManager {
|
|
|
222
219
|
* Advances the current animation by a specified number of frames.
|
|
223
220
|
* @param {number} quantity - The number of frames to advance by.
|
|
224
221
|
*/
|
|
225
|
-
next(quantity: number) {
|
|
222
|
+
public next(quantity: number) {
|
|
226
223
|
if (this.currentAnim) {
|
|
227
224
|
this.currentAnim.next(quantity);
|
|
228
225
|
this.currentFrame = this.currentAnim.currentFrame;
|
|
@@ -233,7 +230,7 @@ export class AnimationManager {
|
|
|
233
230
|
* Moves the current animation back by a specified number of frames.
|
|
234
231
|
* @param {number} quantity - The number of frames to move back by.
|
|
235
232
|
*/
|
|
236
|
-
previous(quantity: number) {
|
|
233
|
+
public previous(quantity: number) {
|
|
237
234
|
if (this.currentAnim) {
|
|
238
235
|
this.currentAnim.previous(quantity);
|
|
239
236
|
this.currentFrame = this.currentAnim.currentFrame;
|
|
@@ -245,7 +242,7 @@ export class AnimationManager {
|
|
|
245
242
|
* @param {string} name - The name of the animation to retrieve.
|
|
246
243
|
* @returns {Animation} The Animation object, or null if not found.
|
|
247
244
|
*/
|
|
248
|
-
getAnimation(name: string) {
|
|
245
|
+
public getAnimation(name: string) {
|
|
249
246
|
if (name && this._anims[name]) {
|
|
250
247
|
return this._anims[name];
|
|
251
248
|
}
|
|
@@ -255,7 +252,7 @@ export class AnimationManager {
|
|
|
255
252
|
/**
|
|
256
253
|
* Refreshes the current frame texture (not implemented).
|
|
257
254
|
*/
|
|
258
|
-
refreshFrame() {
|
|
255
|
+
public refreshFrame() {
|
|
259
256
|
// TODO
|
|
260
257
|
this.game.logger.warn('animation_manager.refreshFrame() is not implemented');
|
|
261
258
|
// this.sprite.setTexture(PIXI.TextureCache[this.currentFrame.uuid]);
|
|
@@ -263,9 +260,9 @@ export class AnimationManager {
|
|
|
263
260
|
|
|
264
261
|
/**
|
|
265
262
|
* Gets the frame data used by this AnimationManager.
|
|
266
|
-
* @returns {
|
|
263
|
+
* @returns {FrameData} The FrameData object.
|
|
267
264
|
*/
|
|
268
|
-
get frameData() {
|
|
265
|
+
public get frameData() {
|
|
269
266
|
return this._frameData;
|
|
270
267
|
}
|
|
271
268
|
|
|
@@ -273,7 +270,7 @@ export class AnimationManager {
|
|
|
273
270
|
* Gets the total number of frames in the frame data.
|
|
274
271
|
* @returns {number} The total number of frames.
|
|
275
272
|
*/
|
|
276
|
-
get frameTotal() {
|
|
273
|
+
public get frameTotal() {
|
|
277
274
|
return this._frameData.total;
|
|
278
275
|
}
|
|
279
276
|
|
|
@@ -281,14 +278,14 @@ export class AnimationManager {
|
|
|
281
278
|
* Gets the paused state of the current animation.
|
|
282
279
|
* @returns {boolean} True if the current animation is paused, false otherwise.
|
|
283
280
|
*/
|
|
284
|
-
get paused() {
|
|
281
|
+
public get paused() {
|
|
285
282
|
return this.currentAnim.isPaused;
|
|
286
283
|
}
|
|
287
284
|
|
|
288
285
|
/**
|
|
289
286
|
* Sets the paused state of the current animation.
|
|
290
287
|
*/
|
|
291
|
-
set paused(value) {
|
|
288
|
+
public set paused(value) {
|
|
292
289
|
this.currentAnim.paused = value;
|
|
293
290
|
}
|
|
294
291
|
|
|
@@ -296,7 +293,7 @@ export class AnimationManager {
|
|
|
296
293
|
* Gets the name of the current animation.
|
|
297
294
|
* @returns {string} The name of the current animation, or null if no animation is active.
|
|
298
295
|
*/
|
|
299
|
-
get name() {
|
|
296
|
+
public get name() {
|
|
300
297
|
if (this.currentAnim) {
|
|
301
298
|
return this.currentAnim.name;
|
|
302
299
|
}
|
|
@@ -307,7 +304,7 @@ export class AnimationManager {
|
|
|
307
304
|
* Gets the current frame index.
|
|
308
305
|
* @returns {number} The current frame index.
|
|
309
306
|
*/
|
|
310
|
-
get frame() {
|
|
307
|
+
public get frame() {
|
|
311
308
|
if (this.currentFrame) {
|
|
312
309
|
return this.currentFrame.index;
|
|
313
310
|
}
|
|
@@ -317,7 +314,7 @@ export class AnimationManager {
|
|
|
317
314
|
/**
|
|
318
315
|
* Sets the current frame index.
|
|
319
316
|
*/
|
|
320
|
-
set frame(value) {
|
|
317
|
+
public set frame(value) {
|
|
321
318
|
if (typeof value === 'number' && this._frameData && this._frameData.getFrame(value) !== null) {
|
|
322
319
|
this.currentFrame = this._frameData.getFrame(value);
|
|
323
320
|
if (this.currentFrame) {
|
|
@@ -335,7 +332,7 @@ export class AnimationManager {
|
|
|
335
332
|
* Gets the current frame name.
|
|
336
333
|
* @returns {string} The current frame name, or null if no frame is set.
|
|
337
334
|
*/
|
|
338
|
-
get frameName() {
|
|
335
|
+
public get frameName() {
|
|
339
336
|
if (this.currentFrame) {
|
|
340
337
|
return this.currentFrame.name;
|
|
341
338
|
}
|
|
@@ -345,7 +342,7 @@ export class AnimationManager {
|
|
|
345
342
|
/**
|
|
346
343
|
* Sets the current frame by name.
|
|
347
344
|
*/
|
|
348
|
-
set frameName(value) {
|
|
345
|
+
public set frameName(value) {
|
|
349
346
|
if (typeof value === 'string' && this._frameData && this._frameData.getFrameByName(value) !== null) {
|
|
350
347
|
this.currentFrame = this._frameData.getFrameByName(value);
|
|
351
348
|
if (this.currentFrame) {
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { Frame } from './frame.js';
|
|
2
2
|
import { FrameData } from './frame_data.js';
|
|
3
|
+
import type { Game } from './game.js';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* TBD.
|
|
6
|
-
* @param {
|
|
7
|
+
* @param {Game} game - TBD.
|
|
7
8
|
* @param {string} key - TBD.
|
|
8
9
|
* @param {number} frameWidth - TBD.
|
|
9
10
|
* @param {number} frameHeight - TBD.
|
|
@@ -13,7 +14,7 @@ import { FrameData } from './frame_data.js';
|
|
|
13
14
|
* @returns {FrameData} TBD.
|
|
14
15
|
*/
|
|
15
16
|
export const spriteSheet = (
|
|
16
|
-
game:
|
|
17
|
+
game: Game,
|
|
17
18
|
key: any,
|
|
18
19
|
frameWidth: number,
|
|
19
20
|
frameHeight: number,
|
|
@@ -28,8 +29,8 @@ export const spriteSheet = (
|
|
|
28
29
|
if (img === null) {
|
|
29
30
|
return null;
|
|
30
31
|
}
|
|
31
|
-
const width = img
|
|
32
|
-
const height = img
|
|
32
|
+
const { width } = img;
|
|
33
|
+
const { height } = img;
|
|
33
34
|
if (frameWidth <= 0) {
|
|
34
35
|
frameWidth = Math.floor(-width / Math.min(-1, frameWidth));
|
|
35
36
|
}
|
|
@@ -66,11 +67,11 @@ export const spriteSheet = (
|
|
|
66
67
|
|
|
67
68
|
/**
|
|
68
69
|
* TBD.
|
|
69
|
-
* @param {
|
|
70
|
+
* @param {Game} game - TBD.
|
|
70
71
|
* @param {object} json - TBD.
|
|
71
72
|
* @returns {FrameData} TBD.
|
|
72
73
|
*/
|
|
73
|
-
export const JSONDataHash = (game:
|
|
74
|
+
export const JSONDataHash = (game: Game, json: any, _key?: any) => {
|
|
74
75
|
if (!json.frames) {
|
|
75
76
|
game.logger.warn('JSONDataHash: Invalid Texture Atlas JSON given, missing frames object', json);
|
|
76
77
|
return null;
|
|
@@ -78,12 +79,11 @@ export const JSONDataHash = (game: import('./game.js').Game, json: any, _key?: a
|
|
|
78
79
|
// Let's create some frames then
|
|
79
80
|
const data = new FrameData();
|
|
80
81
|
// By this stage frames is a fully parsed array
|
|
81
|
-
const frames = json
|
|
82
|
+
const { frames } = json;
|
|
82
83
|
let newFrame;
|
|
83
84
|
let i = 0;
|
|
84
85
|
const keys = Object.keys(frames);
|
|
85
|
-
for (
|
|
86
|
-
const key = keys[k];
|
|
86
|
+
for (const key of keys) {
|
|
87
87
|
newFrame = data.addFrame(
|
|
88
88
|
new Frame(i, frames[key].frame.x, frames[key].frame.y, frames[key].frame.w, frames[key].frame.h, key)
|
|
89
89
|
);
|