@vpmedia/phaser 1.0.1 → 1.0.2
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/phaser.cjs.LICENSE.txt +1 -1
- package/dist/phaser.js.LICENSE.txt +1 -1
- package/package.json +2 -3
- package/src/index.js +99 -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 +130 -0
- package/src/phaser/core/array_set.js +108 -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 +386 -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 +31 -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 +946 -0
- package/src/phaser/core/loader_parser.js +105 -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 +66 -0
- package/src/phaser/core/scene_manager.js +310 -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 +365 -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 +316 -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 +121 -0
- package/src/phaser/display/canvas/renderer.js +123 -0
- package/src/phaser/display/canvas/tinter.js +141 -0
- package/src/phaser/display/canvas/util.js +151 -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 +14 -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 +248 -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 +647 -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 +618 -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 +32 -0
- package/src/phaser/display/webgl/util.js +74 -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 +141 -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 +115 -0
- package/src/phaser/geom/util/ellipse.js +30 -0
- package/src/phaser/geom/util/line.js +130 -0
- package/src/phaser/geom/util/matrix.js +48 -0
- package/src/phaser/geom/util/point.js +276 -0
- package/src/phaser/geom/util/polygon.js +24 -0
- package/src/phaser/geom/util/rectangle.js +212 -0
- package/src/phaser/geom/util/rounded_rectangle.js +28 -0
- package/src/phaser/util/math.js +279 -0
- package/src/phaser/util/string.js +26 -0
|
@@ -0,0 +1,276 @@
|
|
|
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
|
+
import TimerEvent from './timer_event';
|
|
8
|
+
|
|
9
|
+
export default class {
|
|
10
|
+
|
|
11
|
+
constructor(game, autoDestroy = false) {
|
|
12
|
+
this.game = game;
|
|
13
|
+
this.running = false;
|
|
14
|
+
this.autoDestroy = autoDestroy;
|
|
15
|
+
this.expired = false;
|
|
16
|
+
this.elapsed = 0;
|
|
17
|
+
this.events = [];
|
|
18
|
+
this.onComplete = new Signal();
|
|
19
|
+
this.nextTick = 0;
|
|
20
|
+
this.timeCap = 1000;
|
|
21
|
+
this.paused = false;
|
|
22
|
+
this._codePaused = false;
|
|
23
|
+
this._started = 0;
|
|
24
|
+
this._pauseStarted = 0;
|
|
25
|
+
this._pauseTotal = 0;
|
|
26
|
+
this._now = Date.now();
|
|
27
|
+
this._len = 0;
|
|
28
|
+
this._marked = 0;
|
|
29
|
+
this._i = 0;
|
|
30
|
+
this._diff = 0;
|
|
31
|
+
this._newTick = 0;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
create(delay, loop, repeatCount, callback, callbackContext, args) {
|
|
35
|
+
const roundedDelay = Math.round(delay);
|
|
36
|
+
let tick = roundedDelay;
|
|
37
|
+
if (this._now === 0) {
|
|
38
|
+
tick += this.game.time.time;
|
|
39
|
+
} else {
|
|
40
|
+
tick += this._now;
|
|
41
|
+
}
|
|
42
|
+
const event = new TimerEvent(this, roundedDelay, tick, repeatCount, loop, callback, callbackContext, args);
|
|
43
|
+
this.events.push(event);
|
|
44
|
+
this.order();
|
|
45
|
+
this.expired = false;
|
|
46
|
+
return event;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
add(delay, callback, callbackContext, ...args) {
|
|
50
|
+
return this.create(delay, false, 0, callback, callbackContext, args);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
repeat(delay, repeatCount, callback, callbackContext, ...args) {
|
|
54
|
+
return this.create(delay, false, repeatCount, callback, callbackContext, args);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
loop(delay, callback, callbackContext, ...args) {
|
|
58
|
+
return this.create(delay, true, 0, callback, callbackContext, args);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
start(delay) {
|
|
62
|
+
if (this.running) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
this._started = this.game.time.time + (delay || 0);
|
|
66
|
+
this.running = true;
|
|
67
|
+
for (let i = 0; i < this.events.length; i += 1) {
|
|
68
|
+
this.events[i].tick = this.events[i].delay + this._started;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
stop(clearEvents = true) {
|
|
73
|
+
this.running = false;
|
|
74
|
+
if (clearEvents) {
|
|
75
|
+
this.events.length = 0;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
remove(event) {
|
|
80
|
+
for (let i = 0; i < this.events.length; i += 1) {
|
|
81
|
+
if (this.events[i] === event) {
|
|
82
|
+
this.events[i].pendingDelete = true;
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
order() {
|
|
90
|
+
if (this.events.length > 0) {
|
|
91
|
+
// Sort the events so the one with the lowest tick is first
|
|
92
|
+
this.events.sort(this.sortHandler);
|
|
93
|
+
this.nextTick = this.events[0].tick;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
sortHandler(a, b) {
|
|
98
|
+
if (a.tick < b.tick) {
|
|
99
|
+
return -1;
|
|
100
|
+
} else if (a.tick > b.tick) {
|
|
101
|
+
return 1;
|
|
102
|
+
}
|
|
103
|
+
return 0;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
clearPendingEvents() {
|
|
107
|
+
this._i = this.events.length;
|
|
108
|
+
while (this._i) {
|
|
109
|
+
this._i -= 1;
|
|
110
|
+
if (this.events[this._i].pendingDelete) {
|
|
111
|
+
this.events.splice(this._i, 1);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
this._len = this.events.length;
|
|
115
|
+
this._i = 0;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
update(time) {
|
|
119
|
+
if (this.paused) {
|
|
120
|
+
return true;
|
|
121
|
+
}
|
|
122
|
+
this.elapsed = time - this._now;
|
|
123
|
+
this._now = time;
|
|
124
|
+
// spike-dislike
|
|
125
|
+
if (this.elapsed > this.timeCap) {
|
|
126
|
+
// For some reason the time between now and the last time the game was updated was larger than our timeCap.
|
|
127
|
+
// This can happen if the Game.config.disableVisibilityChange is true and you swap tabs, which makes the raf pause.
|
|
128
|
+
// In this case we need to adjust the TimerEvents and nextTick.
|
|
129
|
+
this.adjustEvents(time - this.elapsed);
|
|
130
|
+
}
|
|
131
|
+
this._marked = 0;
|
|
132
|
+
// Clears events marked for deletion and resets _len and _i to 0.
|
|
133
|
+
this.clearPendingEvents();
|
|
134
|
+
if (this.running && this._now >= this.nextTick && this._len > 0) {
|
|
135
|
+
while (this._i < this._len && this.running) {
|
|
136
|
+
if (this._now >= this.events[this._i].tick && !this.events[this._i].pendingDelete) {
|
|
137
|
+
// (now + delay) - (time difference from last tick to now)
|
|
138
|
+
this._newTick = (this._now + this.events[this._i].delay) - (this._now - this.events[this._i].tick);
|
|
139
|
+
if (this._newTick < 0) {
|
|
140
|
+
this._newTick = this._now + this.events[this._i].delay;
|
|
141
|
+
}
|
|
142
|
+
if (this.events[this._i].loop === true) {
|
|
143
|
+
this.events[this._i].tick = this._newTick;
|
|
144
|
+
this.events[this._i].callback.apply(this.events[this._i].callbackContext, this.events[this._i].args);
|
|
145
|
+
} else if (this.events[this._i].repeatCount > 0) {
|
|
146
|
+
this.events[this._i].repeatCount -= 1;
|
|
147
|
+
this.events[this._i].tick = this._newTick;
|
|
148
|
+
this.events[this._i].callback.apply(this.events[this._i].callbackContext, this.events[this._i].args);
|
|
149
|
+
} else {
|
|
150
|
+
this._marked += 1;
|
|
151
|
+
this.events[this._i].pendingDelete = true;
|
|
152
|
+
this.events[this._i].callback.apply(this.events[this._i].callbackContext, this.events[this._i].args);
|
|
153
|
+
}
|
|
154
|
+
this._i += 1;
|
|
155
|
+
} else {
|
|
156
|
+
break;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
// Are there any events left?
|
|
160
|
+
if (this.events.length > this._marked) {
|
|
161
|
+
this.order();
|
|
162
|
+
} else {
|
|
163
|
+
this.expired = true;
|
|
164
|
+
this.onComplete.dispatch(this);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
if (this.expired && this.autoDestroy) {
|
|
168
|
+
return false;
|
|
169
|
+
}
|
|
170
|
+
return true;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
pause() {
|
|
174
|
+
if (!this.running) {
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
this._codePaused = true;
|
|
178
|
+
if (this.paused) {
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
this._pauseStarted = this.game.time.time;
|
|
182
|
+
this.paused = true;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
_pause() {
|
|
186
|
+
if (this.paused || !this.running) {
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
this._pauseStarted = this.game.time.time;
|
|
190
|
+
this.paused = true;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
adjustEvents(baseTime) {
|
|
194
|
+
for (let i = 0; i < this.events.length; i += 1) {
|
|
195
|
+
if (!this.events[i].pendingDelete) {
|
|
196
|
+
// Work out how long there would have been from when the game paused until the events next tick
|
|
197
|
+
let t = this.events[i].tick - baseTime;
|
|
198
|
+
if (t < 0) {
|
|
199
|
+
t = 0;
|
|
200
|
+
}
|
|
201
|
+
// Add the difference on to the time now
|
|
202
|
+
this.events[i].tick = this._now + t;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
const d = this.nextTick - baseTime;
|
|
206
|
+
if (d < 0) {
|
|
207
|
+
this.nextTick = this._now;
|
|
208
|
+
} else {
|
|
209
|
+
this.nextTick = this._now + d;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
resume() {
|
|
214
|
+
if (!this.paused) {
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
const now = this.game.time.time;
|
|
218
|
+
this._pauseTotal += now - this._now;
|
|
219
|
+
this._now = now;
|
|
220
|
+
this.adjustEvents(this._pauseStarted);
|
|
221
|
+
this.paused = false;
|
|
222
|
+
this._codePaused = false;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
_resume() {
|
|
226
|
+
if (this._codePaused) {
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
this.resume();
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
removeAll() {
|
|
233
|
+
this.onComplete.removeAll();
|
|
234
|
+
this.events.length = 0;
|
|
235
|
+
this._len = 0;
|
|
236
|
+
this._i = 0;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
destroy() {
|
|
240
|
+
this.onComplete.removeAll();
|
|
241
|
+
this.running = false;
|
|
242
|
+
this.events = [];
|
|
243
|
+
this._len = 0;
|
|
244
|
+
this._i = 0;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
get next() {
|
|
248
|
+
return this.nextTick;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
get duration() {
|
|
252
|
+
if (this.running && this.nextTick > this._now) {
|
|
253
|
+
return this.nextTick - this._now;
|
|
254
|
+
}
|
|
255
|
+
return 0;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
get length() {
|
|
259
|
+
return this.events.length;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
get ms() {
|
|
263
|
+
if (this.running) {
|
|
264
|
+
return this._now - this._started - this._pauseTotal;
|
|
265
|
+
}
|
|
266
|
+
return 0;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
get seconds() {
|
|
270
|
+
if (this.running) {
|
|
271
|
+
return this.ms * 0.001;
|
|
272
|
+
}
|
|
273
|
+
return 0;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
|
|
7
|
+
export default class {
|
|
8
|
+
|
|
9
|
+
constructor(timer, delay, tick, repeatCount, loop, callback, callbackContext, args) {
|
|
10
|
+
this.timer = timer;
|
|
11
|
+
this.delay = delay;
|
|
12
|
+
this.tick = tick;
|
|
13
|
+
this.repeatCount = repeatCount - 1;
|
|
14
|
+
this.loop = loop;
|
|
15
|
+
this.callback = callback;
|
|
16
|
+
this.callbackContext = callbackContext;
|
|
17
|
+
this.args = args;
|
|
18
|
+
this.pendingDelete = false;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
}
|
|
@@ -0,0 +1,329 @@
|
|
|
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
|
+
import TweenData from './tween_data';
|
|
8
|
+
import * as MathUtils from '../util/math';
|
|
9
|
+
import { TWEEN_PENDING, TWEEN_RUNNING, TWEEN_COMPLETE, TWEEN_LOOPED } from './const';
|
|
10
|
+
|
|
11
|
+
export default class {
|
|
12
|
+
|
|
13
|
+
constructor(target, game, manager) {
|
|
14
|
+
this.game = game;
|
|
15
|
+
this.target = target;
|
|
16
|
+
this.manager = manager;
|
|
17
|
+
this.timeline = [];
|
|
18
|
+
this.reverse = false;
|
|
19
|
+
this.timeScale = 1;
|
|
20
|
+
this.repeatCounter = 0;
|
|
21
|
+
this.pendingDelete = false;
|
|
22
|
+
this.onStart = new Signal();
|
|
23
|
+
this.onLoop = new Signal();
|
|
24
|
+
this.onRepeat = new Signal();
|
|
25
|
+
this.onChildComplete = new Signal();
|
|
26
|
+
this.onComplete = new Signal();
|
|
27
|
+
this.isRunning = false;
|
|
28
|
+
this.current = 0;
|
|
29
|
+
this.properties = {};
|
|
30
|
+
this.chainedTween = null;
|
|
31
|
+
this.isPaused = false;
|
|
32
|
+
this.frameBased = manager.frameBased;
|
|
33
|
+
this._onUpdateCallback = null;
|
|
34
|
+
this._onUpdateCallbackContext = null;
|
|
35
|
+
this._pausedTime = 0;
|
|
36
|
+
this._codePaused = false;
|
|
37
|
+
this._hasStarted = false;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
to(properties, duration = 1000, ease = 'Linear', autoStart = false, delay = 0, repeat = 0, yoyo = false) {
|
|
41
|
+
if (typeof ease === 'string' && this.manager.easeMap[ease]) {
|
|
42
|
+
ease = this.manager.easeMap[ease];
|
|
43
|
+
}
|
|
44
|
+
if (this.isRunning) {
|
|
45
|
+
return this;
|
|
46
|
+
}
|
|
47
|
+
this.timeline.push(new TweenData(this).to(properties, duration, ease, delay, repeat, yoyo));
|
|
48
|
+
if (autoStart) {
|
|
49
|
+
this.start();
|
|
50
|
+
}
|
|
51
|
+
return this;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
from(properties, duration = 1000, ease = 'Linear', autoStart = false, delay = 0, repeat = 0, yoyo = false) {
|
|
55
|
+
if (typeof ease === 'string' && this.manager.easeMap[ease]) {
|
|
56
|
+
ease = this.manager.easeMap[ease];
|
|
57
|
+
}
|
|
58
|
+
if (this.isRunning) {
|
|
59
|
+
console.warn('Tween.from cannot be called after Tween.start');
|
|
60
|
+
return this;
|
|
61
|
+
}
|
|
62
|
+
this.timeline.push(new TweenData(this).from(properties, duration, ease, delay, repeat, yoyo));
|
|
63
|
+
if (autoStart) {
|
|
64
|
+
this.start();
|
|
65
|
+
}
|
|
66
|
+
return this;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
start(index = 0) {
|
|
70
|
+
if (this.game === null || this.target === null || this.timeline.length === 0 || this.isRunning) {
|
|
71
|
+
return this;
|
|
72
|
+
}
|
|
73
|
+
// Populate the tween data
|
|
74
|
+
for (let i = 0; i < this.timeline.length; i += 1) {
|
|
75
|
+
// Build our master property list with the starting values
|
|
76
|
+
const keys = Object.keys(this.timeline[i].vEnd);
|
|
77
|
+
for (let k = 0; k < keys.length; k += 1) {
|
|
78
|
+
const property = keys[k];
|
|
79
|
+
this.properties[property] = this.target[property] || 0;
|
|
80
|
+
if (!Array.isArray(this.properties[property])) {
|
|
81
|
+
// Ensures we're using numbers, not strings
|
|
82
|
+
this.properties[property] *= 1.0;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
for (let i = 0; i < this.timeline.length; i += 1) {
|
|
87
|
+
this.timeline[i].loadValues();
|
|
88
|
+
}
|
|
89
|
+
this.manager.add(this);
|
|
90
|
+
this.isRunning = true;
|
|
91
|
+
if (index < 0 || index > this.timeline.length - 1) {
|
|
92
|
+
index = 0;
|
|
93
|
+
}
|
|
94
|
+
this.current = index;
|
|
95
|
+
this.timeline[this.current].start();
|
|
96
|
+
return this;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
stop(complete = false) {
|
|
100
|
+
this.isRunning = false;
|
|
101
|
+
this._onUpdateCallback = null;
|
|
102
|
+
this._onUpdateCallbackContext = null;
|
|
103
|
+
if (complete) {
|
|
104
|
+
this.onComplete.dispatch(this.target, this);
|
|
105
|
+
this._hasStarted = false;
|
|
106
|
+
if (this.chainedTween) {
|
|
107
|
+
this.chainedTween.start();
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
this.manager.remove(this);
|
|
111
|
+
return this;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
updateTweenData(property, value, index = 0) {
|
|
115
|
+
if (this.timeline.length === 0) {
|
|
116
|
+
return this;
|
|
117
|
+
}
|
|
118
|
+
if (index === -1) {
|
|
119
|
+
for (let i = 0; i < this.timeline.length; i += 1) {
|
|
120
|
+
this.timeline[i][property] = value;
|
|
121
|
+
}
|
|
122
|
+
} else {
|
|
123
|
+
this.timeline[index][property] = value;
|
|
124
|
+
}
|
|
125
|
+
return this;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
delay(duration, index) {
|
|
129
|
+
return this.updateTweenData('delay', duration, index);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
repeat(total, repeatDelay = 0, index = 0) {
|
|
133
|
+
this.updateTweenData('repeatCounter', total, index);
|
|
134
|
+
return this.updateTweenData('repeatDelay', repeatDelay, index);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
repeatDelay(duration, index) {
|
|
138
|
+
return this.updateTweenData('repeatDelay', duration, index);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
yoyo(enable, yoyoDelay = 0, index = 0) {
|
|
142
|
+
this.updateTweenData('yoyo', enable, index);
|
|
143
|
+
return this.updateTweenData('yoyoDelay', yoyoDelay, index);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
yoyoDelay(duration, index) {
|
|
147
|
+
return this.updateTweenData('yoyoDelay', duration, index);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
easing(ease, index) {
|
|
151
|
+
if (typeof ease === 'string' && this.manager.easeMap[ease]) {
|
|
152
|
+
ease = this.manager.easeMap[ease];
|
|
153
|
+
}
|
|
154
|
+
return this.updateTweenData('easingFunction', ease, index);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
interpolation(interpolation, context = MathUtils, index = 0) {
|
|
158
|
+
this.updateTweenData('interpolationFunction', interpolation, index);
|
|
159
|
+
return this.updateTweenData('interpolationContext', context, index);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
repeatAll(total = 0) {
|
|
163
|
+
this.repeatCounter = total;
|
|
164
|
+
return this;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
chain(...args) {
|
|
168
|
+
let i = args.length;
|
|
169
|
+
while (i) {
|
|
170
|
+
i -= 1;
|
|
171
|
+
if (i > 0) {
|
|
172
|
+
args[i - 1].chainedTween = args[i];
|
|
173
|
+
} else {
|
|
174
|
+
this.chainedTween = args[i];
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return this;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
loop(value = true) {
|
|
181
|
+
this.repeatCounter = (value) ? -1 : 0;
|
|
182
|
+
return this;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
onUpdateCallback(callback, callbackContext) {
|
|
186
|
+
this._onUpdateCallback = callback;
|
|
187
|
+
this._onUpdateCallbackContext = callbackContext;
|
|
188
|
+
return this;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
pause() {
|
|
192
|
+
this.isPaused = true;
|
|
193
|
+
this._codePaused = true;
|
|
194
|
+
this._pausedTime = this.game.time.time;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
_pause() {
|
|
198
|
+
if (!this._codePaused) {
|
|
199
|
+
this.isPaused = true;
|
|
200
|
+
this._pausedTime = this.game.time.time;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
resume() {
|
|
205
|
+
if (this.isPaused) {
|
|
206
|
+
this.isPaused = false;
|
|
207
|
+
this._codePaused = false;
|
|
208
|
+
for (let i = 0; i < this.timeline.length; i += 1) {
|
|
209
|
+
if (!this.timeline[i].isRunning) {
|
|
210
|
+
this.timeline[i].startTime += (this.game.time.time - this._pausedTime);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
_resume() {
|
|
217
|
+
if (!this._codePaused) {
|
|
218
|
+
this.resume();
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
update(time) {
|
|
223
|
+
if (this.pendingDelete || !this.target) {
|
|
224
|
+
return false;
|
|
225
|
+
}
|
|
226
|
+
if (this.isPaused) {
|
|
227
|
+
return true;
|
|
228
|
+
}
|
|
229
|
+
const status = this.timeline[this.current].update(time);
|
|
230
|
+
if (status === TWEEN_PENDING) {
|
|
231
|
+
return true;
|
|
232
|
+
} else if (status === TWEEN_RUNNING) {
|
|
233
|
+
if (!this._hasStarted) {
|
|
234
|
+
this.onStart.dispatch(this.target, this);
|
|
235
|
+
this._hasStarted = true;
|
|
236
|
+
}
|
|
237
|
+
if (this._onUpdateCallback !== null) {
|
|
238
|
+
this._onUpdateCallback.call(this._onUpdateCallbackContext, this, this.timeline[this.current].value, this.timeline[this.current]);
|
|
239
|
+
}
|
|
240
|
+
// In case the update callback modifies this tween
|
|
241
|
+
return this.isRunning;
|
|
242
|
+
} else if (status === TWEEN_LOOPED) {
|
|
243
|
+
if (this.timeline[this.current].repeatCounter === -1) {
|
|
244
|
+
this.onLoop.dispatch(this.target, this);
|
|
245
|
+
} else {
|
|
246
|
+
this.onRepeat.dispatch(this.target, this);
|
|
247
|
+
}
|
|
248
|
+
return true;
|
|
249
|
+
} else if (status === TWEEN_COMPLETE) {
|
|
250
|
+
let complete = false;
|
|
251
|
+
// What now?
|
|
252
|
+
if (this.reverse) {
|
|
253
|
+
this.current -= 1;
|
|
254
|
+
if (this.current < 0) {
|
|
255
|
+
this.current = this.timeline.length - 1;
|
|
256
|
+
complete = true;
|
|
257
|
+
}
|
|
258
|
+
} else {
|
|
259
|
+
this.current += 1;
|
|
260
|
+
if (this.current === this.timeline.length) {
|
|
261
|
+
this.current = 0;
|
|
262
|
+
complete = true;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
if (complete) {
|
|
266
|
+
// We've reached the start or end of the child tweens (depending on Tween.reverse), should we repeat it?
|
|
267
|
+
if (this.repeatCounter === -1) {
|
|
268
|
+
this.timeline[this.current].start();
|
|
269
|
+
this.onLoop.dispatch(this.target, this);
|
|
270
|
+
return true;
|
|
271
|
+
} else if (this.repeatCounter > 0) {
|
|
272
|
+
this.repeatCounter -= 1;
|
|
273
|
+
|
|
274
|
+
this.timeline[this.current].start();
|
|
275
|
+
this.onRepeat.dispatch(this.target, this);
|
|
276
|
+
return true;
|
|
277
|
+
}
|
|
278
|
+
// No more repeats and no more children, so we're done
|
|
279
|
+
this.isRunning = false;
|
|
280
|
+
this.onComplete.dispatch(this.target, this);
|
|
281
|
+
this._hasStarted = false;
|
|
282
|
+
if (this.chainedTween) {
|
|
283
|
+
this.chainedTween.start();
|
|
284
|
+
}
|
|
285
|
+
return false;
|
|
286
|
+
}
|
|
287
|
+
// We've still got some children to go
|
|
288
|
+
this.onChildComplete.dispatch(this.target, this);
|
|
289
|
+
this.timeline[this.current].start();
|
|
290
|
+
return true;
|
|
291
|
+
}
|
|
292
|
+
return false;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
generateData(frameRate = 60, data = []) {
|
|
296
|
+
if (this.game === null || this.target === null) {
|
|
297
|
+
return null;
|
|
298
|
+
}
|
|
299
|
+
// Populate the tween data
|
|
300
|
+
for (let i = 0; i < this.timeline.length; i += 1) {
|
|
301
|
+
// Build our master property list with the starting values
|
|
302
|
+
const keys = Object.keys(this.timeline[i].vEnd);
|
|
303
|
+
for (let k = 0; k < keys.length; k += 1) {
|
|
304
|
+
const property = keys[k];
|
|
305
|
+
this.properties[property] = this.target[property] || 0;
|
|
306
|
+
if (!Array.isArray(this.properties[property])) {
|
|
307
|
+
// Ensures we're using numbers, not strings
|
|
308
|
+
this.properties[property] *= 1.0;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
for (let i = 0; i < this.timeline.length; i += 1) {
|
|
313
|
+
this.timeline[i].loadValues();
|
|
314
|
+
}
|
|
315
|
+
for (let i = 0; i < this.timeline.length; i += 1) {
|
|
316
|
+
data = data.concat(this.timeline[i].generateData(frameRate));
|
|
317
|
+
}
|
|
318
|
+
return data;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
get totalDuration() {
|
|
322
|
+
let total = 0;
|
|
323
|
+
for (let i = 0; i < this.timeline.length; i += 1) {
|
|
324
|
+
total += this.timeline[i].duration;
|
|
325
|
+
}
|
|
326
|
+
return total;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
}
|