@vpmedia/phaser 1.0.1 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -3
- package/dist/phaser.cjs +1 -1
- package/dist/phaser.cjs.LICENSE.txt +1 -1
- package/dist/phaser.cjs.map +1 -1
- package/dist/phaser.js +1 -1
- package/dist/phaser.js.LICENSE.txt +1 -1
- package/dist/phaser.js.map +1 -1
- package/package.json +23 -17
- package/src/index.js +142 -0
- package/src/phaser/core/animation.js +355 -0
- package/src/phaser/core/animation_manager.js +238 -0
- package/src/phaser/core/animation_parser.js +133 -0
- package/src/phaser/core/array_set.js +107 -0
- package/src/phaser/core/cache.js +558 -0
- package/src/phaser/core/const.js +106 -0
- package/src/phaser/core/device.js +67 -0
- package/src/phaser/core/device_util.js +388 -0
- package/src/phaser/core/dom.js +207 -0
- package/src/phaser/core/event_manager.js +243 -0
- package/src/phaser/core/factory.js +74 -0
- package/src/phaser/core/frame.js +75 -0
- package/src/phaser/core/frame_data.js +84 -0
- package/src/phaser/core/frame_util.js +33 -0
- package/src/phaser/core/game.js +412 -0
- package/src/phaser/core/input.js +401 -0
- package/src/phaser/core/input_button.js +102 -0
- package/src/phaser/core/input_handler.js +687 -0
- package/src/phaser/core/input_mouse.js +289 -0
- package/src/phaser/core/input_mspointer.js +197 -0
- package/src/phaser/core/input_pointer.js +427 -0
- package/src/phaser/core/input_touch.js +157 -0
- package/src/phaser/core/loader.js +1057 -0
- package/src/phaser/core/loader_parser.js +109 -0
- package/src/phaser/core/raf.js +46 -0
- package/src/phaser/core/raf_fb.js +75 -0
- package/src/phaser/core/raf_to.js +34 -0
- package/src/phaser/core/scale_manager.js +806 -0
- package/src/phaser/core/scene.js +65 -0
- package/src/phaser/core/scene_manager.js +309 -0
- package/src/phaser/core/signal.js +175 -0
- package/src/phaser/core/signal_binding.js +69 -0
- package/src/phaser/core/sound.js +538 -0
- package/src/phaser/core/sound_manager.js +364 -0
- package/src/phaser/core/stage.js +108 -0
- package/src/phaser/core/time.js +203 -0
- package/src/phaser/core/timer.js +276 -0
- package/src/phaser/core/timer_event.js +21 -0
- package/src/phaser/core/tween.js +329 -0
- package/src/phaser/core/tween_data.js +258 -0
- package/src/phaser/core/tween_easing.js +341 -0
- package/src/phaser/core/tween_manager.js +185 -0
- package/src/phaser/core/world.js +18 -0
- package/src/phaser/display/bitmap_text.js +322 -0
- package/src/phaser/display/button.js +194 -0
- package/src/phaser/display/canvas/buffer.js +36 -0
- package/src/phaser/display/canvas/graphics.js +227 -0
- package/src/phaser/display/canvas/masker.js +39 -0
- package/src/phaser/display/canvas/pool.js +126 -0
- package/src/phaser/display/canvas/renderer.js +123 -0
- package/src/phaser/display/canvas/tinter.js +144 -0
- package/src/phaser/display/canvas/util.js +159 -0
- package/src/phaser/display/display_object.js +597 -0
- package/src/phaser/display/graphics.js +723 -0
- package/src/phaser/display/graphics_data.js +27 -0
- package/src/phaser/display/graphics_data_util.js +15 -0
- package/src/phaser/display/group.js +227 -0
- package/src/phaser/display/image.js +288 -0
- package/src/phaser/display/sprite_batch.js +15 -0
- package/src/phaser/display/sprite_util.js +250 -0
- package/src/phaser/display/text.js +1089 -0
- package/src/phaser/display/webgl/abstract_filter.js +25 -0
- package/src/phaser/display/webgl/base_texture.js +68 -0
- package/src/phaser/display/webgl/blend_manager.js +35 -0
- package/src/phaser/display/webgl/earcut.js +662 -0
- package/src/phaser/display/webgl/earcut_node.js +28 -0
- package/src/phaser/display/webgl/fast_sprite_batch.js +242 -0
- package/src/phaser/display/webgl/filter_manager.js +46 -0
- package/src/phaser/display/webgl/filter_texture.js +61 -0
- package/src/phaser/display/webgl/graphics.js +624 -0
- package/src/phaser/display/webgl/graphics_data.js +42 -0
- package/src/phaser/display/webgl/mask_manager.js +36 -0
- package/src/phaser/display/webgl/render_texture.js +81 -0
- package/src/phaser/display/webgl/renderer.js +234 -0
- package/src/phaser/display/webgl/shader/complex.js +74 -0
- package/src/phaser/display/webgl/shader/fast.js +97 -0
- package/src/phaser/display/webgl/shader/normal.js +225 -0
- package/src/phaser/display/webgl/shader/primitive.js +72 -0
- package/src/phaser/display/webgl/shader/strip.js +77 -0
- package/src/phaser/display/webgl/shader_manager.js +89 -0
- package/src/phaser/display/webgl/sprite_batch.js +320 -0
- package/src/phaser/display/webgl/stencil_manager.js +170 -0
- package/src/phaser/display/webgl/texture.js +117 -0
- package/src/phaser/display/webgl/texture_util.js +34 -0
- package/src/phaser/display/webgl/util.js +78 -0
- package/src/phaser/geom/circle.js +186 -0
- package/src/phaser/geom/ellipse.js +65 -0
- package/src/phaser/geom/line.js +190 -0
- package/src/phaser/geom/matrix.js +147 -0
- package/src/phaser/geom/point.js +164 -0
- package/src/phaser/geom/polygon.js +140 -0
- package/src/phaser/geom/rectangle.js +306 -0
- package/src/phaser/geom/rounded_rectangle.js +36 -0
- package/src/phaser/geom/util/circle.js +122 -0
- package/src/phaser/geom/util/ellipse.js +34 -0
- package/src/phaser/geom/util/line.js +135 -0
- package/src/phaser/geom/util/matrix.js +53 -0
- package/src/phaser/geom/util/point.js +296 -0
- package/src/phaser/geom/util/polygon.js +28 -0
- package/src/phaser/geom/util/rectangle.js +229 -0
- package/src/phaser/geom/util/rounded_rectangle.js +32 -0
- package/src/phaser/util/math.js +297 -0
- package/src/phaser/util/string.js +32 -0
package/package.json
CHANGED
|
@@ -1,47 +1,53 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vpmedia/phaser",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
|
+
"description": "@vpmedia/phaser is the modern ECMAScript port of the popular Phaser game engine v2.6.2",
|
|
4
5
|
"author": "Andras Csizmadia <andras@vpmedia.hu> (www.vpmedia.hu)",
|
|
5
6
|
"license": "MIT",
|
|
6
|
-
"homepage": "https://github.com/vpmedia/phaser",
|
|
7
|
-
"
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
"homepage": "https://github.com/vpmedia/phaser#readme",
|
|
8
|
+
"bugs": {
|
|
9
|
+
"url": "https://github.com/vpmedia/phaser/issues"
|
|
10
|
+
},
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/vpmedia/phaser.git"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"phaser"
|
|
17
|
+
],
|
|
18
|
+
"main": "./src/index.js",
|
|
10
19
|
"devDependencies": {
|
|
11
20
|
"@babel/cli": "^7.19.3",
|
|
12
21
|
"@babel/core": "^7.19.6",
|
|
13
22
|
"@babel/eslint-parser": "^7.19.1",
|
|
14
23
|
"@babel/preset-env": "^7.19.4",
|
|
15
24
|
"@babel/register": "^7.18.9",
|
|
16
|
-
"babel-loader": "^8.
|
|
17
|
-
"chai": "^4.3.6",
|
|
25
|
+
"babel-loader": "^8.3.0",
|
|
18
26
|
"eslint": "^8.26.0",
|
|
19
27
|
"eslint-config-prettier": "^8.5.0",
|
|
20
28
|
"eslint-plugin-import": "^2.26.0",
|
|
21
|
-
"eslint-plugin-
|
|
29
|
+
"eslint-plugin-jest": "^27.1.3",
|
|
30
|
+
"eslint-plugin-jsdoc": "^39.6.2",
|
|
22
31
|
"eslint-plugin-prettier": "^4.2.1",
|
|
23
32
|
"husky": "^8.0.1",
|
|
33
|
+
"jest": "^29.2.2",
|
|
24
34
|
"lint-staged": "^13.0.3",
|
|
25
|
-
"mocha": "^10.1.0",
|
|
26
|
-
"mocha-junit-reporter": "^2.1.1",
|
|
27
35
|
"prettier": "^2.7.1",
|
|
28
|
-
"sinon": "^14.0.1",
|
|
29
|
-
"sinon-chai": "^3.7.0",
|
|
30
36
|
"webpack": "^5.74.0",
|
|
31
37
|
"webpack-cli": "^4.10.0"
|
|
32
38
|
},
|
|
33
39
|
"scripts": {
|
|
34
40
|
"prebuild": "rm -rf ./dist && mkdir -p ./dist",
|
|
35
41
|
"build": "webpack --config webpack.config.babel.js --mode production",
|
|
36
|
-
"test": "
|
|
37
|
-
"lint": "eslint
|
|
38
|
-
"lint-fix": "eslint
|
|
42
|
+
"test": "jest --passWithNoTests",
|
|
43
|
+
"lint": "eslint \"**/*.js\"",
|
|
44
|
+
"lint-fix": "eslint \"**/*.js\" --fix",
|
|
39
45
|
"format": "prettier --write \"**/*.{js,json}\"",
|
|
40
46
|
"lint-staged": "lint-staged",
|
|
41
47
|
"prepack": "npm run build"
|
|
42
48
|
},
|
|
43
49
|
"engines": {
|
|
44
|
-
"npm": ">=
|
|
45
|
-
"node": ">=
|
|
50
|
+
"npm": ">=7.0.0",
|
|
51
|
+
"node": ">=16.0.0"
|
|
46
52
|
}
|
|
47
53
|
}
|
package/src/index.js
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author Andras Csizmadia <andras@vpmedia.hu>
|
|
3
|
+
* @author Richard Davey <rich@photonstorm.com>
|
|
4
|
+
* @copyright Copyright (c) 2018-present Richard Davey, Photon Storm Ltd., Andras Csizmadia <andras@vpmedia.hu> (www.vpmedia.hu)
|
|
5
|
+
*/
|
|
6
|
+
import * as Const from './phaser/core/const';
|
|
7
|
+
import AnimationManager from './phaser/core/animation_manager';
|
|
8
|
+
import * as AnimationParser from './phaser/core/animation_parser';
|
|
9
|
+
import ArraySet from './phaser/core/array_set';
|
|
10
|
+
import Device from './phaser/core/device';
|
|
11
|
+
import * as DeviceUtils from './phaser/core/device_util';
|
|
12
|
+
import DOM from './phaser/core/dom';
|
|
13
|
+
import EventManager from './phaser/core/event_manager';
|
|
14
|
+
import Frame from './phaser/core/frame';
|
|
15
|
+
import FrameData from './phaser/core/frame_data';
|
|
16
|
+
import InputManager from './phaser/core/input';
|
|
17
|
+
import InputMouse from './phaser/core/input_mouse';
|
|
18
|
+
import InputMSPointer from './phaser/core/input_mspointer';
|
|
19
|
+
import InputPointer from './phaser/core/input_pointer';
|
|
20
|
+
import InputTouch from './phaser/core/input_touch';
|
|
21
|
+
import Loader from './phaser/core/loader';
|
|
22
|
+
import GameLoopRAF from './phaser/core/raf';
|
|
23
|
+
import GameLoopTO from './phaser/core/raf_to';
|
|
24
|
+
import GameLoopFB from './phaser/core/raf_fb';
|
|
25
|
+
import ScaleManager from './phaser/core/scale_manager';
|
|
26
|
+
import Scene from './phaser/core/scene';
|
|
27
|
+
import SceneManager from './phaser/core/scene_manager';
|
|
28
|
+
import Signal from './phaser/core/signal';
|
|
29
|
+
import SignalBinding from './phaser/core/signal_binding';
|
|
30
|
+
import Sound from './phaser/core/sound';
|
|
31
|
+
import SoundManager from './phaser/core/sound_manager';
|
|
32
|
+
import Time from './phaser/core/time';
|
|
33
|
+
import Timer from './phaser/core/timer';
|
|
34
|
+
import TimerEvent from './phaser/core/timer_event';
|
|
35
|
+
import Tween from './phaser/core/tween';
|
|
36
|
+
import TweenData from './phaser/core/tween_data';
|
|
37
|
+
import * as TweenEasing from './phaser/core/tween_easing';
|
|
38
|
+
import TweenManager from './phaser/core/tween_manager';
|
|
39
|
+
import Circle from './phaser/geom/circle';
|
|
40
|
+
import Ellipse from './phaser/geom/ellipse';
|
|
41
|
+
import Line from './phaser/geom/line';
|
|
42
|
+
import Matrix from './phaser/geom/matrix';
|
|
43
|
+
import Point from './phaser/geom/point';
|
|
44
|
+
import Polygon from './phaser/geom/polygon';
|
|
45
|
+
import Rectangle from './phaser/geom/rectangle';
|
|
46
|
+
import * as MathUtils from './phaser/util/math';
|
|
47
|
+
import * as StringUtils from './phaser/util/string';
|
|
48
|
+
import RoundedRectangle from './phaser/geom/rounded_rectangle';
|
|
49
|
+
import * as CircleUtils from './phaser/geom/util/circle';
|
|
50
|
+
import * as EllipseUtils from './phaser/geom/util/ellipse';
|
|
51
|
+
import * as LineUtils from './phaser/geom/util/line';
|
|
52
|
+
import * as MatrixUtils from './phaser/geom/util/matrix';
|
|
53
|
+
import * as PointUtils from './phaser/geom/util/point';
|
|
54
|
+
import * as PolygonUtils from './phaser/geom/util/polygon';
|
|
55
|
+
import * as RectangleUtils from './phaser/geom/util/rectangle';
|
|
56
|
+
import * as RoundedRectangleUtils from './phaser/geom/util/rounded_rectangle';
|
|
57
|
+
import GraphicsData from './phaser/display/graphics_data';
|
|
58
|
+
import * as CanvasPool from './phaser/display/canvas/pool';
|
|
59
|
+
import * as CanvasUtils from './phaser/display/canvas/util';
|
|
60
|
+
import * as CanvasTinter from './phaser/display/canvas/tinter';
|
|
61
|
+
import * as CanvasMasker from './phaser/display/canvas/masker';
|
|
62
|
+
import * as CanvasGraphics from './phaser/display/canvas/graphics';
|
|
63
|
+
import CanvasBuffer from './phaser/display/canvas/buffer';
|
|
64
|
+
import CanvasRenderer from './phaser/display/canvas/renderer';
|
|
65
|
+
import * as EarCut from './phaser/display/webgl/earcut';
|
|
66
|
+
import Game from './phaser/core/game';
|
|
67
|
+
import BitmapText from './phaser/display/bitmap_text';
|
|
68
|
+
import DisplayObject from './phaser/display/display_object';
|
|
69
|
+
import Button from './phaser/display/button';
|
|
70
|
+
import Image from './phaser/display/image';
|
|
71
|
+
import Group from './phaser/display/group';
|
|
72
|
+
import Text from './phaser/display/text';
|
|
73
|
+
|
|
74
|
+
export {
|
|
75
|
+
Const,
|
|
76
|
+
AnimationManager,
|
|
77
|
+
AnimationParser,
|
|
78
|
+
ArraySet,
|
|
79
|
+
DOM,
|
|
80
|
+
Device,
|
|
81
|
+
DeviceUtils,
|
|
82
|
+
EventManager,
|
|
83
|
+
Frame,
|
|
84
|
+
FrameData,
|
|
85
|
+
InputManager,
|
|
86
|
+
InputMouse,
|
|
87
|
+
InputMSPointer,
|
|
88
|
+
InputPointer,
|
|
89
|
+
InputTouch,
|
|
90
|
+
Loader,
|
|
91
|
+
GameLoopRAF,
|
|
92
|
+
GameLoopTO,
|
|
93
|
+
GameLoopFB,
|
|
94
|
+
MathUtils,
|
|
95
|
+
StringUtils,
|
|
96
|
+
ScaleManager,
|
|
97
|
+
Scene,
|
|
98
|
+
SceneManager,
|
|
99
|
+
Signal,
|
|
100
|
+
SignalBinding,
|
|
101
|
+
Sound,
|
|
102
|
+
SoundManager,
|
|
103
|
+
Time,
|
|
104
|
+
Timer,
|
|
105
|
+
TimerEvent,
|
|
106
|
+
Tween,
|
|
107
|
+
TweenData,
|
|
108
|
+
TweenEasing,
|
|
109
|
+
TweenManager,
|
|
110
|
+
Circle,
|
|
111
|
+
CircleUtils,
|
|
112
|
+
Ellipse,
|
|
113
|
+
EllipseUtils,
|
|
114
|
+
Line,
|
|
115
|
+
LineUtils,
|
|
116
|
+
Matrix,
|
|
117
|
+
MatrixUtils,
|
|
118
|
+
Point,
|
|
119
|
+
PointUtils,
|
|
120
|
+
Polygon,
|
|
121
|
+
PolygonUtils,
|
|
122
|
+
Rectangle,
|
|
123
|
+
RectangleUtils,
|
|
124
|
+
RoundedRectangle,
|
|
125
|
+
RoundedRectangleUtils,
|
|
126
|
+
Game,
|
|
127
|
+
GraphicsData,
|
|
128
|
+
CanvasPool,
|
|
129
|
+
CanvasUtils,
|
|
130
|
+
CanvasBuffer,
|
|
131
|
+
CanvasTinter,
|
|
132
|
+
CanvasMasker,
|
|
133
|
+
CanvasGraphics,
|
|
134
|
+
CanvasRenderer,
|
|
135
|
+
EarCut,
|
|
136
|
+
BitmapText,
|
|
137
|
+
Button,
|
|
138
|
+
DisplayObject,
|
|
139
|
+
Image,
|
|
140
|
+
Group,
|
|
141
|
+
Text,
|
|
142
|
+
};
|
|
@@ -0,0 +1,355 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author Andras Csizmadia <andras@vpmedia.hu>
|
|
3
|
+
* @author Richard Davey <rich@photonstorm.com>
|
|
4
|
+
* @copyright Copyright (c) 2018-present Richard Davey, Photon Storm Ltd., Andras Csizmadia <andras@vpmedia.hu> (www.vpmedia.hu)
|
|
5
|
+
*/
|
|
6
|
+
import Signal from './signal';
|
|
7
|
+
|
|
8
|
+
export default class {
|
|
9
|
+
|
|
10
|
+
constructor(game, parent, name, frameData, frames, frameRate, loop = false) {
|
|
11
|
+
this.game = game;
|
|
12
|
+
this._parent = parent;
|
|
13
|
+
this._frameData = frameData;
|
|
14
|
+
this.name = name;
|
|
15
|
+
this._frames = [];
|
|
16
|
+
this._frames = this._frames.concat(frames);
|
|
17
|
+
this.delay = 1000 / frameRate;
|
|
18
|
+
this.loop = loop;
|
|
19
|
+
this.loopCount = 0;
|
|
20
|
+
this.killOnComplete = false;
|
|
21
|
+
this.isFinished = false;
|
|
22
|
+
this.isPlaying = false;
|
|
23
|
+
this.isPaused = false;
|
|
24
|
+
this._pauseStartTime = 0;
|
|
25
|
+
this._frameIndex = 0;
|
|
26
|
+
this._frameDiff = 0;
|
|
27
|
+
this._frameSkip = 1;
|
|
28
|
+
this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]);
|
|
29
|
+
this.onStart = new Signal();
|
|
30
|
+
this.onUpdate = null;
|
|
31
|
+
this.onComplete = new Signal();
|
|
32
|
+
this.onLoop = new Signal();
|
|
33
|
+
this.isReversed = false;
|
|
34
|
+
// Set-up some event listeners
|
|
35
|
+
this.game.onPause.add(this.onPause, this);
|
|
36
|
+
this.game.onResume.add(this.onResume, this);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
play(frameRate, loop, killOnComplete) {
|
|
40
|
+
if (typeof frameRate === 'number') {
|
|
41
|
+
// If they set a new frame rate then use it, otherwise use the one set on creation
|
|
42
|
+
this.delay = 1000 / frameRate;
|
|
43
|
+
}
|
|
44
|
+
if (typeof loop === 'boolean') {
|
|
45
|
+
// If they set a new loop value then use it, otherwise use the one set on creation
|
|
46
|
+
this.loop = loop;
|
|
47
|
+
}
|
|
48
|
+
if (typeof killOnComplete !== 'undefined') {
|
|
49
|
+
// Remove the parent sprite once the animation has finished?
|
|
50
|
+
this.killOnComplete = killOnComplete;
|
|
51
|
+
}
|
|
52
|
+
this.isPlaying = true;
|
|
53
|
+
this.isFinished = false;
|
|
54
|
+
this.paused = false;
|
|
55
|
+
this.loopCount = 0;
|
|
56
|
+
this._timeLastFrame = this.game.time.time;
|
|
57
|
+
this._timeNextFrame = this.game.time.time + this.delay;
|
|
58
|
+
this._frameIndex = this.isReversed ? this._frames.length - 1 : 0;
|
|
59
|
+
this.updateCurrentFrame(false, true);
|
|
60
|
+
this._parent.events.onAnimationStart$dispatch(this._parent, this);
|
|
61
|
+
this.onStart.dispatch(this._parent, this);
|
|
62
|
+
this._parent.animations.currentAnim = this;
|
|
63
|
+
this._parent.animations.currentFrame = this.currentFrame;
|
|
64
|
+
return this;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
restart() {
|
|
68
|
+
this.isPlaying = true;
|
|
69
|
+
this.isFinished = false;
|
|
70
|
+
this.paused = false;
|
|
71
|
+
this.loopCount = 0;
|
|
72
|
+
this._timeLastFrame = this.game.time.time;
|
|
73
|
+
this._timeNextFrame = this.game.time.time + this.delay;
|
|
74
|
+
this._frameIndex = 0;
|
|
75
|
+
this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]);
|
|
76
|
+
this._parent.setFrame(this.currentFrame);
|
|
77
|
+
this._parent.animations.currentAnim = this;
|
|
78
|
+
this._parent.animations.currentFrame = this.currentFrame;
|
|
79
|
+
this.onStart.dispatch(this._parent, this);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
reverse() {
|
|
83
|
+
this.reversed = !this.reversed;
|
|
84
|
+
return this;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
reverseOnce() {
|
|
88
|
+
this.onComplete.addOnce(this.reverse, this);
|
|
89
|
+
return this.reverse();
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
setFrame(frameId, useLocalFrameIndex = false) {
|
|
93
|
+
let frameIndex;
|
|
94
|
+
// Find the index to the desired frame.
|
|
95
|
+
if (typeof frameId === 'string') {
|
|
96
|
+
for (let i = 0; i < this._frames.length; i += 1) {
|
|
97
|
+
if (this._frameData.getFrame(this._frames[i]).name === frameId) {
|
|
98
|
+
frameIndex = i;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
} else if (typeof frameId === 'number') {
|
|
102
|
+
if (useLocalFrameIndex) {
|
|
103
|
+
frameIndex = frameId;
|
|
104
|
+
} else {
|
|
105
|
+
for (let i = 0; i < this._frames.length; i += 1) {
|
|
106
|
+
if (this._frames[i] === frameId) {
|
|
107
|
+
frameIndex = i;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
if (frameIndex) {
|
|
113
|
+
// Set the current frame index to the found index. Subtract 1 so that it animates to the desired frame on update.
|
|
114
|
+
this._frameIndex = frameIndex - 1;
|
|
115
|
+
// Make the animation update at next update
|
|
116
|
+
this._timeNextFrame = this.game.time.time;
|
|
117
|
+
this.update();
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
stop(resetFrame = false, dispatchComplete = false) {
|
|
122
|
+
this.isPlaying = false;
|
|
123
|
+
this.isFinished = true;
|
|
124
|
+
this.paused = false;
|
|
125
|
+
if (resetFrame) {
|
|
126
|
+
this.currentFrame = this._frameData.getFrame(this._frames[0]);
|
|
127
|
+
if (this.currentFrame) {
|
|
128
|
+
this._parent.setFrame(this.currentFrame);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
if (dispatchComplete) {
|
|
132
|
+
this._parent.events.onAnimationComplete$dispatch(this._parent, this);
|
|
133
|
+
this.onComplete.dispatch(this._parent, this);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
onPause() {
|
|
138
|
+
if (this.isPlaying) {
|
|
139
|
+
this._frameDiff = this._timeNextFrame - this.game.time.time;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
onResume() {
|
|
144
|
+
if (this.isPlaying) {
|
|
145
|
+
this._timeNextFrame = this.game.time.time + this._frameDiff;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
update() {
|
|
150
|
+
if (this.isPaused) {
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
153
|
+
if (this.isPlaying && this.game.time.time >= this._timeNextFrame) {
|
|
154
|
+
this._frameSkip = 1;
|
|
155
|
+
// Lagging?
|
|
156
|
+
this._frameDiff = this.game.time.time - this._timeNextFrame;
|
|
157
|
+
this._timeLastFrame = this.game.time.time;
|
|
158
|
+
if (this._frameDiff > this.delay) {
|
|
159
|
+
// We need to skip a frame, work out how many
|
|
160
|
+
this._frameSkip = Math.floor(this._frameDiff / this.delay);
|
|
161
|
+
this._frameDiff -= (this._frameSkip * this.delay);
|
|
162
|
+
}
|
|
163
|
+
// And what's left now?
|
|
164
|
+
this._timeNextFrame = this.game.time.time + (this.delay - this._frameDiff);
|
|
165
|
+
if (this.isReversed) {
|
|
166
|
+
this._frameIndex -= this._frameSkip;
|
|
167
|
+
} else {
|
|
168
|
+
this._frameIndex += this._frameSkip;
|
|
169
|
+
}
|
|
170
|
+
if (!this.isReversed && this._frameIndex >= this._frames.length || this.isReversed && this._frameIndex <= -1) {
|
|
171
|
+
if (this.loop) {
|
|
172
|
+
// Update current state before event callback
|
|
173
|
+
this._frameIndex = Math.abs(this._frameIndex) % this._frames.length;
|
|
174
|
+
if (this.isReversed) {
|
|
175
|
+
this._frameIndex = this._frames.length - 1 - this._frameIndex;
|
|
176
|
+
}
|
|
177
|
+
this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]);
|
|
178
|
+
// Instead of calling updateCurrentFrame we do it here instead
|
|
179
|
+
if (this.currentFrame) {
|
|
180
|
+
this._parent.setFrame(this.currentFrame);
|
|
181
|
+
}
|
|
182
|
+
this.loopCount += 1;
|
|
183
|
+
this._parent.events.onAnimationLoop$dispatch(this._parent, this);
|
|
184
|
+
this.onLoop.dispatch(this._parent, this);
|
|
185
|
+
if (this.onUpdate) {
|
|
186
|
+
this.onUpdate.dispatch(this, this.currentFrame);
|
|
187
|
+
// False if the animation was destroyed from within a callback
|
|
188
|
+
return !!this._frameData;
|
|
189
|
+
}
|
|
190
|
+
return true;
|
|
191
|
+
}
|
|
192
|
+
this.complete();
|
|
193
|
+
return false;
|
|
194
|
+
}
|
|
195
|
+
return this.updateCurrentFrame(true);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
return false;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
updateCurrentFrame(signalUpdate, fromPlay = false) {
|
|
202
|
+
if (!this._frameData || !this.currentFrame) {
|
|
203
|
+
// The animation is already destroyed, probably from a callback
|
|
204
|
+
return false;
|
|
205
|
+
}
|
|
206
|
+
// Previous index
|
|
207
|
+
const idx = this.currentFrame.index;
|
|
208
|
+
this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]);
|
|
209
|
+
if (this.currentFrame && (fromPlay || (!fromPlay && idx !== this.currentFrame.index))) {
|
|
210
|
+
this._parent.setFrame(this.currentFrame);
|
|
211
|
+
}
|
|
212
|
+
if (this.onUpdate && signalUpdate) {
|
|
213
|
+
this.onUpdate.dispatch(this, this.currentFrame);
|
|
214
|
+
// False if the animation was destroyed from within a callback
|
|
215
|
+
return !!this._frameData;
|
|
216
|
+
}
|
|
217
|
+
return true;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
next(quantity = 1) {
|
|
221
|
+
let frame = this._frameIndex + quantity;
|
|
222
|
+
if (frame >= this._frames.length) {
|
|
223
|
+
if (this.loop) {
|
|
224
|
+
frame %= this._frames.length;
|
|
225
|
+
} else {
|
|
226
|
+
frame = this._frames.length - 1;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
if (frame !== this._frameIndex) {
|
|
230
|
+
this._frameIndex = frame;
|
|
231
|
+
this.updateCurrentFrame(true);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
previous(quantity = 1) {
|
|
236
|
+
let frame = this._frameIndex - quantity;
|
|
237
|
+
if (frame < 0) {
|
|
238
|
+
if (this.loop) {
|
|
239
|
+
frame = this._frames.length + frame;
|
|
240
|
+
} else {
|
|
241
|
+
frame += 1;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
if (frame !== this._frameIndex) {
|
|
245
|
+
this._frameIndex = frame;
|
|
246
|
+
this.updateCurrentFrame(true);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
updateFrameData(frameData) {
|
|
251
|
+
this._frameData = frameData;
|
|
252
|
+
this.currentFrame = this._frameData ? this._frameData.getFrame(this._frames[this._frameIndex % this._frames.length]) : null;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
destroy() {
|
|
256
|
+
if (!this._frameData) {
|
|
257
|
+
// Already destroyed
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
this.game.onPause.remove(this.onPause, this);
|
|
261
|
+
this.game.onResume.remove(this.onResume, this);
|
|
262
|
+
this.game = null;
|
|
263
|
+
this._parent = null;
|
|
264
|
+
this._frames = null;
|
|
265
|
+
this._frameData = null;
|
|
266
|
+
this.currentFrame = null;
|
|
267
|
+
this.isPlaying = false;
|
|
268
|
+
this.onStart.dispose();
|
|
269
|
+
this.onLoop.dispose();
|
|
270
|
+
this.onComplete.dispose();
|
|
271
|
+
if (this.onUpdate) {
|
|
272
|
+
this.onUpdate.dispose();
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
complete() {
|
|
277
|
+
this._frameIndex = this._frames.length - 1;
|
|
278
|
+
this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]);
|
|
279
|
+
this.isPlaying = false;
|
|
280
|
+
this.isFinished = true;
|
|
281
|
+
this.paused = false;
|
|
282
|
+
this._parent.events.onAnimationComplete$dispatch(this._parent, this);
|
|
283
|
+
this.onComplete.dispatch(this._parent, this);
|
|
284
|
+
if (this.killOnComplete) {
|
|
285
|
+
this._parent.kill();
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
get paused() {
|
|
290
|
+
return this.isPaused;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
set paused(value) {
|
|
294
|
+
this.isPaused = value;
|
|
295
|
+
if (value) {
|
|
296
|
+
this._pauseStartTime = this.game.time.time;
|
|
297
|
+
} else if (this.isPlaying) {
|
|
298
|
+
this._timeNextFrame = this.game.time.time + this.delay;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
get reversed() {
|
|
303
|
+
return this.isReversed;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
set reversed(value) {
|
|
307
|
+
this.isReversed = value;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
get frameTotal() {
|
|
311
|
+
return this._frames.length;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
get frame() {
|
|
315
|
+
if (this.currentFrame !== null) {
|
|
316
|
+
return this.currentFrame.index;
|
|
317
|
+
}
|
|
318
|
+
return this._frameIndex;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
set frame(value) {
|
|
322
|
+
this.currentFrame = this._frameData.getFrame(this._frames[value]);
|
|
323
|
+
if (this.currentFrame !== null) {
|
|
324
|
+
this._frameIndex = value;
|
|
325
|
+
this._parent.setFrame(this.currentFrame);
|
|
326
|
+
if (this.onUpdate) {
|
|
327
|
+
this.onUpdate.dispatch(this, this.currentFrame);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
get speed() {
|
|
333
|
+
return 1000 / this.delay;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
set speed(value) {
|
|
337
|
+
if (value > 0) {
|
|
338
|
+
this.delay = 1000 / value;
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
get enableUpdate() {
|
|
343
|
+
return (this.onUpdate !== null);
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
set enableUpdate(value) {
|
|
347
|
+
if (value && this.onUpdate === null) {
|
|
348
|
+
this.onUpdate = new Signal();
|
|
349
|
+
} else if (!value && this.onUpdate !== null) {
|
|
350
|
+
this.onUpdate.dispose();
|
|
351
|
+
this.onUpdate = null;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
}
|