@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,243 @@
|
|
|
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(sprite) {
|
|
11
|
+
this.parent = sprite;
|
|
12
|
+
this._onAddedToGroup = null;
|
|
13
|
+
this._onRemovedFromGroup = null;
|
|
14
|
+
this._onDestroy = null;
|
|
15
|
+
this._onOutOfBounds = null;
|
|
16
|
+
this._onEnterBounds = null;
|
|
17
|
+
this._onInputOver = null;
|
|
18
|
+
this._onInputOut = null;
|
|
19
|
+
this._onInputDown = null;
|
|
20
|
+
this._onInputUp = null;
|
|
21
|
+
this._onDragStart = null;
|
|
22
|
+
this._onDragUpdate = null;
|
|
23
|
+
this._onDragStop = null;
|
|
24
|
+
this._onAnimationStart = null;
|
|
25
|
+
this._onAnimationComplete = null;
|
|
26
|
+
this._onAnimationLoop = null;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
destroy() {
|
|
30
|
+
this._parent = null;
|
|
31
|
+
if (this._onDestroy) { this._onDestroy.dispose(); }
|
|
32
|
+
if (this._onAddedToGroup) { this._onAddedToGroup.dispose(); }
|
|
33
|
+
if (this._onRemovedFromGroup) { this._onRemovedFromGroup.dispose(); }
|
|
34
|
+
if (this._onEnterBounds) { this._onEnterBounds.dispose(); }
|
|
35
|
+
if (this._onOutOfBounds) { this._onOutOfBounds.dispose(); }
|
|
36
|
+
if (this._onInputOver) { this._onInputOver.dispose(); }
|
|
37
|
+
if (this._onInputOut) { this._onInputOut.dispose(); }
|
|
38
|
+
if (this._onInputDown) { this._onInputDown.dispose(); }
|
|
39
|
+
if (this._onInputUp) { this._onInputUp.dispose(); }
|
|
40
|
+
if (this._onDragStart) { this._onDragStart.dispose(); }
|
|
41
|
+
if (this._onDragUpdate) { this._onDragUpdate.dispose(); }
|
|
42
|
+
if (this._onDragStop) { this._onDragStop.dispose(); }
|
|
43
|
+
if (this._onAnimationStart) { this._onAnimationStart.dispose(); }
|
|
44
|
+
if (this._onAnimationComplete) { this._onAnimationComplete.dispose(); }
|
|
45
|
+
if (this._onAnimationLoop) { this._onAnimationLoop.dispose(); }
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
get onAddedToGroup() {
|
|
49
|
+
if (!this._onAddedToGroup) {
|
|
50
|
+
this._onAddedToGroup = new Signal();
|
|
51
|
+
}
|
|
52
|
+
return this._onAddedToGroup;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
onAddedToGroup$dispatch(...args) {
|
|
56
|
+
if (this._onAddedToGroup) {
|
|
57
|
+
this._onAddedToGroup.dispatch(...args);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
get onRemovedFromGroup() {
|
|
62
|
+
if (!this._onRemovedFromGroup) {
|
|
63
|
+
this._onRemovedFromGroup = new Signal();
|
|
64
|
+
}
|
|
65
|
+
return this._onRemovedFromGroup;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
onRemovedFromGroup$dispatch(...args) {
|
|
69
|
+
if (this._onRemovedFromGroup) {
|
|
70
|
+
this._onRemovedFromGroup.dispatch(...args);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
get onDestroy() {
|
|
75
|
+
if (!this._onDestroy) {
|
|
76
|
+
this._onDestroy = new Signal();
|
|
77
|
+
}
|
|
78
|
+
return this._onDestroy;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
onDestroy$dispatch(...args) {
|
|
82
|
+
if (this._onDestroy) {
|
|
83
|
+
this._onDestroy.dispatch(...args);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
get onOutOfBounds() {
|
|
88
|
+
if (!this._onOutOfBounds) {
|
|
89
|
+
this._onOutOfBounds = new Signal();
|
|
90
|
+
}
|
|
91
|
+
return this._onOutOfBounds;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
onOutOfBounds$dispatch(...args) {
|
|
95
|
+
if (this._onOutOfBounds) {
|
|
96
|
+
this._onOutOfBounds.dispatch(...args);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
get onEnterBounds() {
|
|
101
|
+
if (!this._onEnterBounds) {
|
|
102
|
+
this._onEnterBounds = new Signal();
|
|
103
|
+
}
|
|
104
|
+
return this._onEnterBounds;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
onEnterBounds$dispatch(...args) {
|
|
108
|
+
if (this._onEnterBounds) {
|
|
109
|
+
this._onEnterBounds.dispatch(...args);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
get onInputOver() {
|
|
114
|
+
if (!this._onInputOver) {
|
|
115
|
+
this._onInputOver = new Signal();
|
|
116
|
+
}
|
|
117
|
+
return this._onInputOver;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
onInputOver$dispatch(...args) {
|
|
121
|
+
if (this._onInputOver) {
|
|
122
|
+
this._onInputOver.dispatch(...args);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
get onInputOut() {
|
|
127
|
+
if (!this._onInputOut) {
|
|
128
|
+
this._onInputOut = new Signal();
|
|
129
|
+
}
|
|
130
|
+
return this._onInputOut;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
onInputOut$dispatch(...args) {
|
|
134
|
+
if (this._onInputOut) {
|
|
135
|
+
this._onInputOut.dispatch(...args);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
get onInputDown() {
|
|
140
|
+
if (!this._onInputDown) {
|
|
141
|
+
this._onInputDown = new Signal();
|
|
142
|
+
}
|
|
143
|
+
return this._onInputDown;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
onInputDown$dispatch(...args) {
|
|
147
|
+
if (this._onInputDown) {
|
|
148
|
+
this._onInputDown.dispatch(...args);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
get onInputUp() {
|
|
153
|
+
if (!this._onInputUp) {
|
|
154
|
+
this._onInputUp = new Signal();
|
|
155
|
+
}
|
|
156
|
+
return this._onInputUp;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
onInputUp$dispatch(...args) {
|
|
160
|
+
if (this._onInputUp) {
|
|
161
|
+
this._onInputUp.dispatch(...args);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
get onDragStart() {
|
|
166
|
+
if (!this._onDragStart) {
|
|
167
|
+
this._onDragStart = new Signal();
|
|
168
|
+
}
|
|
169
|
+
return this._onDragStart;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
onDragStart$dispatch(...args) {
|
|
173
|
+
if (this._onDragStart) {
|
|
174
|
+
this._onDragStart.dispatch(...args);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
get onDragUpdate() {
|
|
179
|
+
if (!this._onDragUpdate) {
|
|
180
|
+
this._onDragUpdate = new Signal();
|
|
181
|
+
}
|
|
182
|
+
return this._onDragUpdate;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
onDragUpdate$dispatch(...args) {
|
|
186
|
+
if (this._onDragUpdate) {
|
|
187
|
+
this._onDragUpdate.dispatch(...args);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
get onDragStop() {
|
|
192
|
+
if (!this._onDragStop) {
|
|
193
|
+
this._onDragStop = new Signal();
|
|
194
|
+
}
|
|
195
|
+
return this._onDragStop;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
onDragStop$dispatch(...args) {
|
|
199
|
+
if (this._onDragStop) {
|
|
200
|
+
this._onDragStop.dispatch(...args);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
get onAnimationStart() {
|
|
205
|
+
if (!this._onAnimationStart) {
|
|
206
|
+
this._onAnimationStart = new Signal();
|
|
207
|
+
}
|
|
208
|
+
return this._onAnimationStart;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
onAnimationStart$dispatch(...args) {
|
|
212
|
+
if (this._onAnimationStart) {
|
|
213
|
+
this._onAnimationStart.dispatch(...args);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
get onAnimationComplete() {
|
|
218
|
+
if (!this._onAnimationComplete) {
|
|
219
|
+
this._onAnimationComplete = new Signal();
|
|
220
|
+
}
|
|
221
|
+
return this._onAnimationComplete;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
onAnimationComplete$dispatch(...args) {
|
|
225
|
+
if (this._onAnimationComplete) {
|
|
226
|
+
this._onAnimationComplete.dispatch(...args);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
get onAnimationLoop() {
|
|
231
|
+
if (!this._onAnimationLoop) {
|
|
232
|
+
this._onAnimationLoop = new Signal();
|
|
233
|
+
}
|
|
234
|
+
return this._onAnimationLoop;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
onAnimationLoop$dispatch(...args) {
|
|
238
|
+
if (this._onAnimationLoop) {
|
|
239
|
+
this._onAnimationLoop.dispatch(...args);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
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 BitmapText from '../display/bitmap_text';
|
|
7
|
+
import Button from '../display/button';
|
|
8
|
+
import Group from '../display/group';
|
|
9
|
+
import Graphics from '../display/graphics';
|
|
10
|
+
import Image from '../display/image';
|
|
11
|
+
import SpriteBatch from '../display/sprite_batch';
|
|
12
|
+
import Text from '../display/text';
|
|
13
|
+
|
|
14
|
+
export default class {
|
|
15
|
+
|
|
16
|
+
constructor(game) {
|
|
17
|
+
this.game = game;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
existing(object) {
|
|
21
|
+
return this.game.world.add(object);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
image(x, y, key, frame, group = null) {
|
|
25
|
+
if (!group) {
|
|
26
|
+
group = this.game.world;
|
|
27
|
+
}
|
|
28
|
+
return group.add(new Image(this.game, x, y, key, frame));
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
group(parent, name, addToStage) {
|
|
32
|
+
return new Group(this.game, parent, name, addToStage);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
spriteBatch(parent = null, name = 'group', addToStage = false) {
|
|
36
|
+
return new SpriteBatch(this.game, parent, name, addToStage);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
audio(key, volume, loop, connect) {
|
|
40
|
+
console.warn('[GameObjectFactory] game.add.audio() is deprecated, use game.sound.add() directly.');
|
|
41
|
+
return this.game.sound.add(key, volume, loop, connect);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
sound(key, volume, loop, connect) {
|
|
45
|
+
console.warn('[GameObjectFactory] game.add.sound() is deprecated, use game.sound.add() directly.');
|
|
46
|
+
return this.game.sound.add(key, volume, loop, connect);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
text(x, y, text, style, group = null) {
|
|
50
|
+
const parent = group || this.game.world;
|
|
51
|
+
return parent.add(new Text(this.game, x, y, text, style));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
button(x, y, key, callback, callbackContext, overFrame, outFrame, downFrame, upFrame, group = null) {
|
|
55
|
+
const parent = group || this.game.world;
|
|
56
|
+
return parent.add(new Button(this.game, x, y, key, callback, callbackContext, overFrame, outFrame, downFrame, upFrame));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
graphics(x, y, group = null) {
|
|
60
|
+
const parent = group || this.game.world;
|
|
61
|
+
return parent.add(new Graphics(this.game, x, y));
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
bitmapText(x, y, font, text, size, group = null) {
|
|
65
|
+
const parent = group || this.game.world;
|
|
66
|
+
return parent.add(new BitmapText(this.game, x, y, font, text, size));
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
tween(object) {
|
|
70
|
+
console.warn('game.add.tween(target) is deprecated, please use game.tweens.create(target) directly.');
|
|
71
|
+
return this.game.tweens.create(object);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
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 Rectangle from '../geom/rectangle';
|
|
7
|
+
import { distance } from '../util/math';
|
|
8
|
+
import { cloneFrame } from './frame_util';
|
|
9
|
+
|
|
10
|
+
export default class {
|
|
11
|
+
|
|
12
|
+
constructor(index, x, y, width, height, name) {
|
|
13
|
+
this.initialize(index, x, y, width, height, name);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
initialize(index, x, y, width, height, name) {
|
|
17
|
+
this.index = index;
|
|
18
|
+
this.x = x;
|
|
19
|
+
this.y = y;
|
|
20
|
+
this.width = width;
|
|
21
|
+
this.height = height;
|
|
22
|
+
this.name = name;
|
|
23
|
+
this.centerX = Math.floor(width / 2);
|
|
24
|
+
this.centerY = Math.floor(height / 2);
|
|
25
|
+
this.distance = distance(0, 0, width, height);
|
|
26
|
+
this.rotated = false;
|
|
27
|
+
this.rotationDirection = 'cw';
|
|
28
|
+
this.trimmed = false;
|
|
29
|
+
this.sourceSizeW = width;
|
|
30
|
+
this.sourceSizeH = height;
|
|
31
|
+
this.spriteSourceSizeX = 0;
|
|
32
|
+
this.spriteSourceSizeY = 0;
|
|
33
|
+
this.spriteSourceSizeW = 0;
|
|
34
|
+
this.spriteSourceSizeH = 0;
|
|
35
|
+
this.right = this.x + this.width;
|
|
36
|
+
this.bottom = this.y + this.height;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
resize(width, height) {
|
|
40
|
+
this.width = width;
|
|
41
|
+
this.height = height;
|
|
42
|
+
this.centerX = Math.floor(width / 2);
|
|
43
|
+
this.centerY = Math.floor(height / 2);
|
|
44
|
+
this.distance = distance(0, 0, width, height);
|
|
45
|
+
this.sourceSizeW = width;
|
|
46
|
+
this.sourceSizeH = height;
|
|
47
|
+
this.right = this.x + width;
|
|
48
|
+
this.bottom = this.y + height;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
setTrim(trimmed, actualWidth, actualHeight, destX, destY, destWidth, destHeight) {
|
|
52
|
+
this.trimmed = trimmed;
|
|
53
|
+
if (trimmed) {
|
|
54
|
+
this.sourceSizeW = actualWidth;
|
|
55
|
+
this.sourceSizeH = actualHeight;
|
|
56
|
+
this.centerX = Math.floor(actualWidth / 2);
|
|
57
|
+
this.centerY = Math.floor(actualHeight / 2);
|
|
58
|
+
this.spriteSourceSizeX = destX;
|
|
59
|
+
this.spriteSourceSizeY = destY;
|
|
60
|
+
this.spriteSourceSizeW = destWidth;
|
|
61
|
+
this.spriteSourceSizeH = destHeight;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
clone() {
|
|
66
|
+
return cloneFrame(this);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
getRect(output = null) {
|
|
70
|
+
const result = output || new Rectangle();
|
|
71
|
+
result.setTo(this.x, this.y, this.width, this.height);
|
|
72
|
+
return result;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
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 { cloneFrameData } from './frame_util';
|
|
7
|
+
|
|
8
|
+
export default class {
|
|
9
|
+
|
|
10
|
+
constructor() {
|
|
11
|
+
this._frames = [];
|
|
12
|
+
this._frameNames = [];
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
addFrame(frame) {
|
|
16
|
+
frame.index = this._frames.length;
|
|
17
|
+
this._frames.push(frame);
|
|
18
|
+
if (frame.name !== '') {
|
|
19
|
+
this._frameNames[frame.name] = frame.index;
|
|
20
|
+
}
|
|
21
|
+
return frame;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
getFrame(index = 0) {
|
|
25
|
+
if (index >= this._frames.length) {
|
|
26
|
+
index = 0;
|
|
27
|
+
}
|
|
28
|
+
return this._frames[index];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
getFrameByName(name) {
|
|
32
|
+
if (typeof this._frameNames[name] === 'number') {
|
|
33
|
+
return this._frames[this._frameNames[name]];
|
|
34
|
+
}
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
checkFrameName(name) {
|
|
39
|
+
if (this._frameNames[name] == null) {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
clone() {
|
|
46
|
+
return cloneFrameData(this);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
getFrameRange(start, end, output = null) {
|
|
50
|
+
const result = output || [];
|
|
51
|
+
for (let i = start; i <= end; i += 1) {
|
|
52
|
+
result.push(this._frames[i]);
|
|
53
|
+
}
|
|
54
|
+
return result;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
getFrameIndexes(frames, useNumericIndex = true, output = null) {
|
|
58
|
+
const result = output || [];
|
|
59
|
+
if (frames && frames.length > 0) {
|
|
60
|
+
for (let i = 0; i < frames.length; i += 1) {
|
|
61
|
+
if (useNumericIndex && this._frames[frames[i]]) {
|
|
62
|
+
result.push(this._frames[frames[i]].index);
|
|
63
|
+
} else if (this.getFrameByName(frames[i])) {
|
|
64
|
+
result.push(this.getFrameByName(frames[i]).index);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
} else {
|
|
68
|
+
for (let i = 0; i < this._frames.length; i += 1) {
|
|
69
|
+
result.push(this._frames[i].index);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return result;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
destroy() {
|
|
76
|
+
this._frames = null;
|
|
77
|
+
this._frameNames = null;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
get total() {
|
|
81
|
+
return this._frames.length;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
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 Frame from './frame';
|
|
7
|
+
import FrameData from './frame_data';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
*
|
|
11
|
+
* @param frame
|
|
12
|
+
* @param output
|
|
13
|
+
*/
|
|
14
|
+
export function cloneFrame(frame, output = null) {
|
|
15
|
+
const result = output || new Frame();
|
|
16
|
+
result.initialize(frame.index, frame.x, frame.y, frame.width, frame.height);
|
|
17
|
+
return result;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
*
|
|
22
|
+
* @param frameData
|
|
23
|
+
* @param output
|
|
24
|
+
*/
|
|
25
|
+
export function cloneFrameData(frameData, output = null) {
|
|
26
|
+
const result = output || new FrameData();
|
|
27
|
+
for (let i = 0; i < frameData.total; i += 1) {
|
|
28
|
+
result.addFrame(frameData.getFrame(i).clone());
|
|
29
|
+
}
|
|
30
|
+
return result;
|
|
31
|
+
}
|