melonjs 10.2.0 → 10.3.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/README.md +1 -1
- package/dist/melonjs.js +4435 -4283
- package/dist/melonjs.min.js +4 -4
- package/dist/melonjs.module.d.ts +3348 -3833
- package/dist/melonjs.module.js +4025 -3920
- package/package.json +13 -14
- package/src/audio/audio.js +45 -45
- package/src/camera/camera2d.js +78 -101
- package/src/entity/draggable.js +21 -29
- package/src/entity/droptarget.js +24 -31
- package/src/entity/entity.js +34 -38
- package/src/game.js +8 -8
- package/src/{shapes → geometries}/ellipse.js +46 -46
- package/src/{shapes → geometries}/line.js +14 -14
- package/src/{shapes → geometries}/poly.js +103 -54
- package/src/{shapes → geometries}/rectangle.js +73 -120
- package/src/index.js +18 -19
- package/src/input/gamepad.js +20 -20
- package/src/input/input.js +3 -3
- package/src/input/keyboard.js +122 -124
- package/src/input/pointer.js +102 -62
- package/src/input/pointerevent.js +97 -42
- package/src/lang/deprecated.js +29 -18
- package/src/level/level.js +34 -26
- package/src/level/tiled/TMXGroup.js +12 -13
- package/src/level/tiled/TMXLayer.js +41 -42
- package/src/level/tiled/TMXObject.js +76 -70
- package/src/level/tiled/TMXTile.js +13 -15
- package/src/level/tiled/TMXTileMap.js +26 -25
- package/src/level/tiled/TMXTileset.js +14 -15
- package/src/level/tiled/TMXTilesetGroup.js +5 -6
- package/src/level/tiled/TMXUtils.js +13 -11
- package/src/level/tiled/renderer/TMXHexagonalRenderer.js +3 -4
- package/src/level/tiled/renderer/TMXIsometricRenderer.js +3 -4
- package/src/level/tiled/renderer/TMXOrthogonalRenderer.js +2 -3
- package/src/level/tiled/renderer/TMXRenderer.js +18 -19
- package/src/level/tiled/renderer/TMXStaggeredRenderer.js +2 -3
- package/src/loader/loader.js +46 -40
- package/src/loader/loadingscreen.js +7 -7
- package/src/math/color.js +68 -88
- package/src/math/math.js +33 -33
- package/src/math/matrix2.js +70 -71
- package/src/math/matrix3.js +90 -91
- package/src/math/observable_vector2.js +91 -92
- package/src/math/observable_vector3.js +110 -106
- package/src/math/vector2.js +116 -104
- package/src/math/vector3.js +129 -110
- package/src/particles/emitter.js +116 -126
- package/src/particles/particle.js +4 -5
- package/src/particles/particlecontainer.js +2 -3
- package/src/physics/body.js +82 -83
- package/src/physics/bounds.js +64 -66
- package/src/physics/collision.js +21 -22
- package/src/physics/detector.js +13 -13
- package/src/physics/quadtree.js +26 -25
- package/src/physics/sat.js +21 -21
- package/src/physics/world.js +23 -22
- package/src/plugin/plugin.js +12 -13
- package/src/renderable/GUI.js +20 -26
- package/src/renderable/collectable.js +6 -7
- package/src/renderable/colorlayer.js +11 -12
- package/src/renderable/container.js +98 -81
- package/src/renderable/imagelayer.js +33 -35
- package/src/renderable/nineslicesprite.js +15 -16
- package/src/renderable/renderable.js +112 -111
- package/src/renderable/sprite.js +71 -58
- package/src/renderable/trigger.js +17 -19
- package/src/state/stage.js +14 -15
- package/src/state/state.js +78 -78
- package/src/system/device.js +137 -180
- package/src/system/event.js +116 -104
- package/src/system/pooling.js +15 -15
- package/src/system/save.js +9 -6
- package/src/system/timer.js +33 -33
- package/src/text/bitmaptext.js +39 -46
- package/src/text/bitmaptextdata.js +14 -15
- package/src/text/text.js +55 -58
- package/src/tweens/easing.js +5 -5
- package/src/tweens/interpolation.js +5 -5
- package/src/tweens/tween.js +49 -40
- package/src/utils/agent.js +12 -11
- package/src/utils/array.js +8 -8
- package/src/utils/file.js +7 -7
- package/src/utils/function.js +8 -8
- package/src/utils/string.js +19 -19
- package/src/utils/utils.js +23 -23
- package/src/video/canvas/canvas_renderer.js +127 -128
- package/src/video/renderer.js +69 -69
- package/src/video/texture.js +80 -82
- package/src/video/texture_cache.js +2 -4
- package/src/video/video.js +38 -38
- package/src/video/webgl/buffer/vertex.js +11 -3
- package/src/video/webgl/glshader.js +31 -32
- package/src/video/webgl/webgl_compositor.js +145 -127
- package/src/video/webgl/webgl_renderer.js +196 -175
package/src/video/renderer.js
CHANGED
|
@@ -5,31 +5,30 @@ import * as event from "./../system/event.js";
|
|
|
5
5
|
import device from "./../system/device.js";
|
|
6
6
|
import { setPrefixed } from "./../utils/agent.js";
|
|
7
7
|
import { Texture } from "./texture.js";
|
|
8
|
-
import Rect from "./../
|
|
9
|
-
import Ellipse from "./../
|
|
10
|
-
import Polygon from "./../
|
|
11
|
-
import Line from "./../
|
|
8
|
+
import Rect from "./../geometries/rectangle.js";
|
|
9
|
+
import Ellipse from "./../geometries/ellipse.js";
|
|
10
|
+
import Polygon from "./../geometries/poly.js";
|
|
11
|
+
import Line from "./../geometries/line.js";
|
|
12
12
|
import Bounds from "./../physics/bounds.js";
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* @classdesc
|
|
16
16
|
* a base renderer object
|
|
17
17
|
* @class Renderer
|
|
18
|
-
* @
|
|
19
|
-
* @
|
|
20
|
-
* @param {
|
|
21
|
-
* @param {
|
|
22
|
-
* @param {Number} options.height The height of the canvas without scaling
|
|
18
|
+
* @memberof me
|
|
19
|
+
* @param {object} options The renderer parameters
|
|
20
|
+
* @param {number} options.width The width of the canvas without scaling
|
|
21
|
+
* @param {number} options.height The height of the canvas without scaling
|
|
23
22
|
* @param {HTMLCanvasElement} [options.canvas] The html canvas to draw to on screen
|
|
24
|
-
* @param {
|
|
25
|
-
* @param {
|
|
26
|
-
* @param {
|
|
27
|
-
* @param {
|
|
28
|
-
* @param {
|
|
29
|
-
* @param {
|
|
30
|
-
* @param {
|
|
31
|
-
* @param {
|
|
32
|
-
* @param {
|
|
23
|
+
* @param {boolean} [options.doubleBuffering=false] Whether to enable double buffering
|
|
24
|
+
* @param {boolean} [options.antiAlias=false] Whether to enable anti-aliasing, use false (default) for a pixelated effect.
|
|
25
|
+
* @param {boolean} [options.failIfMajorPerformanceCaveat=true] If true, the renderer will switch to CANVAS mode if the performances of a WebGL context would be dramatically lower than that of a native application making equivalent OpenGL calls.
|
|
26
|
+
* @param {boolean} [options.transparent=false] Whether to enable transparency on the canvas (performance hit when enabled)
|
|
27
|
+
* @param {boolean} [options.blendMode="normal"] the default blend mode to use ("normal", "multiply")
|
|
28
|
+
* @param {boolean} [options.subPixel=false] Whether to enable subpixel rendering (performance hit when enabled)
|
|
29
|
+
* @param {boolean} [options.verbose=false] Enable the verbose mode that provides additional details as to what the renderer is doing
|
|
30
|
+
* @param {number} [options.zoomX=width] The actual width of the canvas with scaling applied
|
|
31
|
+
* @param {number} [options.zoomY=height] The actual height of the canvas with scaling applied
|
|
33
32
|
*/
|
|
34
33
|
class Renderer {
|
|
35
34
|
|
|
@@ -38,17 +37,17 @@ class Renderer {
|
|
|
38
37
|
* The given constructor options
|
|
39
38
|
* @public
|
|
40
39
|
* @name settings
|
|
41
|
-
* @
|
|
42
|
-
* @enum {
|
|
40
|
+
* @memberof me.Renderer#
|
|
41
|
+
* @enum {object}
|
|
43
42
|
*/
|
|
44
43
|
this.settings = options;
|
|
45
44
|
|
|
46
45
|
/**
|
|
47
46
|
* true if the current rendering context is valid
|
|
48
47
|
* @name isContextValid
|
|
49
|
-
* @
|
|
48
|
+
* @memberof me.Renderer
|
|
50
49
|
* @default true
|
|
51
|
-
* type {
|
|
50
|
+
* type {boolean}
|
|
52
51
|
*/
|
|
53
52
|
this.isContextValid = true;
|
|
54
53
|
|
|
@@ -104,7 +103,7 @@ class Renderer {
|
|
|
104
103
|
/**
|
|
105
104
|
* prepare the framebuffer for drawing a new frame
|
|
106
105
|
* @name clear
|
|
107
|
-
* @
|
|
106
|
+
* @memberof me.Renderer.prototype
|
|
108
107
|
* @function
|
|
109
108
|
*/
|
|
110
109
|
clear() {}
|
|
@@ -112,7 +111,7 @@ class Renderer {
|
|
|
112
111
|
/**
|
|
113
112
|
* Reset context state
|
|
114
113
|
* @name reset
|
|
115
|
-
* @
|
|
114
|
+
* @memberof me.Renderer.prototype
|
|
116
115
|
* @function
|
|
117
116
|
*/
|
|
118
117
|
reset() {
|
|
@@ -130,9 +129,9 @@ class Renderer {
|
|
|
130
129
|
/**
|
|
131
130
|
* return a reference to the system canvas
|
|
132
131
|
* @name getCanvas
|
|
133
|
-
* @
|
|
132
|
+
* @memberof me.Renderer.prototype
|
|
134
133
|
* @function
|
|
135
|
-
* @
|
|
134
|
+
* @returns {HTMLCanvasElement}
|
|
136
135
|
*/
|
|
137
136
|
getCanvas() {
|
|
138
137
|
return this.backBufferCanvas;
|
|
@@ -141,9 +140,9 @@ class Renderer {
|
|
|
141
140
|
/**
|
|
142
141
|
* return a reference to the screen canvas
|
|
143
142
|
* @name getScreenCanvas
|
|
144
|
-
* @
|
|
143
|
+
* @memberof me.Renderer.prototype
|
|
145
144
|
* @function
|
|
146
|
-
* @
|
|
145
|
+
* @returns {HTMLCanvasElement}
|
|
147
146
|
*/
|
|
148
147
|
getScreenCanvas() {
|
|
149
148
|
return this.canvas;
|
|
@@ -153,9 +152,9 @@ class Renderer {
|
|
|
153
152
|
* return a reference to the screen canvas corresponding 2d Context<br>
|
|
154
153
|
* (will return buffered context if double buffering is enabled, or a reference to the Screen Context)
|
|
155
154
|
* @name getScreenContext
|
|
156
|
-
* @
|
|
155
|
+
* @memberof me.Renderer.prototype
|
|
157
156
|
* @function
|
|
158
|
-
* @
|
|
157
|
+
* @returns {CanvasRenderingContext2D}
|
|
159
158
|
*/
|
|
160
159
|
getScreenContext() {
|
|
161
160
|
return this.context;
|
|
@@ -164,9 +163,9 @@ class Renderer {
|
|
|
164
163
|
/**
|
|
165
164
|
* returns the current blend mode for this renderer
|
|
166
165
|
* @name getBlendMode
|
|
167
|
-
* @
|
|
166
|
+
* @memberof me.Renderer.prototype
|
|
168
167
|
* @function
|
|
169
|
-
* @
|
|
168
|
+
* @returns {string} blend mode
|
|
170
169
|
*/
|
|
171
170
|
getBlendMode() {
|
|
172
171
|
return this.currentBlendMode;
|
|
@@ -176,21 +175,21 @@ class Renderer {
|
|
|
176
175
|
* Returns the 2D Context object of the given Canvas<br>
|
|
177
176
|
* Also configures anti-aliasing and blend modes based on constructor options.
|
|
178
177
|
* @name getContext2d
|
|
179
|
-
* @
|
|
178
|
+
* @memberof me.Renderer.prototype
|
|
180
179
|
* @function
|
|
181
180
|
* @param {HTMLCanvasElement} canvas
|
|
182
|
-
* @param {
|
|
183
|
-
* @
|
|
181
|
+
* @param {boolean} [transparent=true] use false to disable transparency
|
|
182
|
+
* @returns {CanvasRenderingContext2D}
|
|
184
183
|
*/
|
|
185
|
-
getContext2d(
|
|
186
|
-
if (typeof
|
|
184
|
+
getContext2d(canvas, transparent) {
|
|
185
|
+
if (typeof canvas === "undefined" || canvas === null) {
|
|
187
186
|
throw new Error(
|
|
188
187
|
"You must pass a canvas element in order to create " +
|
|
189
188
|
"a 2d context"
|
|
190
189
|
);
|
|
191
190
|
}
|
|
192
191
|
|
|
193
|
-
if (typeof
|
|
192
|
+
if (typeof canvas.getContext === "undefined") {
|
|
194
193
|
throw new Error(
|
|
195
194
|
"Your browser does not support HTML5 canvas."
|
|
196
195
|
);
|
|
@@ -200,12 +199,12 @@ class Renderer {
|
|
|
200
199
|
transparent = true;
|
|
201
200
|
}
|
|
202
201
|
|
|
203
|
-
var _context =
|
|
202
|
+
var _context = canvas.getContext("2d", {
|
|
204
203
|
"alpha" : transparent
|
|
205
204
|
});
|
|
206
205
|
|
|
207
206
|
if (!_context.canvas) {
|
|
208
|
-
_context.canvas =
|
|
207
|
+
_context.canvas = canvas;
|
|
209
208
|
}
|
|
210
209
|
this.setAntiAlias(_context, this.settings.antiAlias);
|
|
211
210
|
return _context;
|
|
@@ -214,9 +213,9 @@ class Renderer {
|
|
|
214
213
|
/**
|
|
215
214
|
* return the width of the system Canvas
|
|
216
215
|
* @name getWidth
|
|
217
|
-
* @
|
|
216
|
+
* @memberof me.Renderer.prototype
|
|
218
217
|
* @function
|
|
219
|
-
* @
|
|
218
|
+
* @returns {number}
|
|
220
219
|
*/
|
|
221
220
|
getWidth() {
|
|
222
221
|
return this.backBufferCanvas.width;
|
|
@@ -225,9 +224,9 @@ class Renderer {
|
|
|
225
224
|
/**
|
|
226
225
|
* return the height of the system Canvas
|
|
227
226
|
* @name getHeight
|
|
228
|
-
* @
|
|
227
|
+
* @memberof me.Renderer.prototype
|
|
229
228
|
* @function
|
|
230
|
-
* @
|
|
229
|
+
* @returns {number} height of the system Canvas
|
|
231
230
|
*/
|
|
232
231
|
getHeight() {
|
|
233
232
|
return this.backBufferCanvas.height;
|
|
@@ -236,9 +235,9 @@ class Renderer {
|
|
|
236
235
|
/**
|
|
237
236
|
* get the current fill & stroke style color.
|
|
238
237
|
* @name getColor
|
|
239
|
-
* @
|
|
238
|
+
* @memberof me.Renderer.prototype
|
|
240
239
|
* @function
|
|
241
|
-
* @
|
|
240
|
+
* @returns {me.Color} current global color
|
|
242
241
|
*/
|
|
243
242
|
getColor() {
|
|
244
243
|
return this.currentColor;
|
|
@@ -247,9 +246,9 @@ class Renderer {
|
|
|
247
246
|
/**
|
|
248
247
|
* return the current global alpha
|
|
249
248
|
* @name globalAlpha
|
|
250
|
-
* @
|
|
249
|
+
* @memberof me.Renderer.prototype
|
|
251
250
|
* @function
|
|
252
|
-
* @
|
|
251
|
+
* @returns {number}
|
|
253
252
|
*/
|
|
254
253
|
globalAlpha() {
|
|
255
254
|
return this.currentColor.glArray[3];
|
|
@@ -258,10 +257,10 @@ class Renderer {
|
|
|
258
257
|
/**
|
|
259
258
|
* check if the given rect or bounds overlaps with the renderer screen coordinates
|
|
260
259
|
* @name overlaps
|
|
261
|
-
* @
|
|
260
|
+
* @memberof me.Renderer.prototype
|
|
262
261
|
* @function
|
|
263
262
|
* @param {me.Rect|me.Bounds} bounds
|
|
264
|
-
* @
|
|
263
|
+
* @returns {boolean} true if overlaps
|
|
265
264
|
*/
|
|
266
265
|
overlaps(bounds) {
|
|
267
266
|
return (
|
|
@@ -274,10 +273,10 @@ class Renderer {
|
|
|
274
273
|
/**
|
|
275
274
|
* resizes the system canvas
|
|
276
275
|
* @name resize
|
|
277
|
-
* @
|
|
276
|
+
* @memberof me.Renderer.prototype
|
|
278
277
|
* @function
|
|
279
|
-
* @param {
|
|
280
|
-
* @param {
|
|
278
|
+
* @param {number} width new width of the canvas
|
|
279
|
+
* @param {number} height new height of the canvas
|
|
281
280
|
*/
|
|
282
281
|
resize(width, height) {
|
|
283
282
|
if (width !== this.backBufferCanvas.width || height !== this.backBufferCanvas.height) {
|
|
@@ -295,10 +294,10 @@ class Renderer {
|
|
|
295
294
|
/**
|
|
296
295
|
* enable/disable image smoothing (scaling interpolation) for the given context
|
|
297
296
|
* @name setAntiAlias
|
|
298
|
-
* @
|
|
297
|
+
* @memberof me.Renderer.prototype
|
|
299
298
|
* @function
|
|
300
|
-
* @param {
|
|
301
|
-
* @param {
|
|
299
|
+
* @param {CanvasRenderingContext2D} context
|
|
300
|
+
* @param {boolean} [enable=false]
|
|
302
301
|
*/
|
|
303
302
|
setAntiAlias(context, enable) {
|
|
304
303
|
var canvas = context.canvas;
|
|
@@ -325,7 +324,7 @@ class Renderer {
|
|
|
325
324
|
/**
|
|
326
325
|
* set/change the current projection matrix (WebGL only)
|
|
327
326
|
* @name setProjection
|
|
328
|
-
* @
|
|
327
|
+
* @memberof me.Renderer.prototype
|
|
329
328
|
* @function
|
|
330
329
|
* @param {me.Matrix3d} matrix
|
|
331
330
|
*/
|
|
@@ -336,9 +335,10 @@ class Renderer {
|
|
|
336
335
|
/**
|
|
337
336
|
* stroke the given shape
|
|
338
337
|
* @name stroke
|
|
339
|
-
* @
|
|
338
|
+
* @memberof me.Renderer.prototype
|
|
340
339
|
* @function
|
|
341
340
|
* @param {me.Rect|me.Polygon|me.Line|me.Ellipse} shape a shape object to stroke
|
|
341
|
+
* @param {boolean} [fill=false] fill the shape with the current color if true
|
|
342
342
|
*/
|
|
343
343
|
stroke(shape, fill) {
|
|
344
344
|
if (shape instanceof Rect || shape instanceof Bounds) {
|
|
@@ -359,12 +359,12 @@ class Renderer {
|
|
|
359
359
|
/**
|
|
360
360
|
* tint the given image or canvas using the given color
|
|
361
361
|
* @name tint
|
|
362
|
-
* @
|
|
362
|
+
* @memberof me.Renderer.prototype
|
|
363
363
|
* @function
|
|
364
|
-
* @param {HTMLImageElement|HTMLCanvasElement|OffscreenCanvas}
|
|
365
|
-
* @param {me.Color|
|
|
366
|
-
* @param {
|
|
367
|
-
* @
|
|
364
|
+
* @param {HTMLImageElement|HTMLCanvasElement|OffscreenCanvas} src the source image to be tinted
|
|
365
|
+
* @param {me.Color|string} color the color that will be used to tint the image
|
|
366
|
+
* @param {string} [mode="multiply"] the composition mode used to tint the image
|
|
367
|
+
* @returns {HTMLCanvasElement|OffscreenCanvas} a new canvas element representing the tinted image
|
|
368
368
|
*/
|
|
369
369
|
tint(src, color, mode) {
|
|
370
370
|
var canvas = createCanvas(src.width, src.height, true);
|
|
@@ -388,7 +388,7 @@ class Renderer {
|
|
|
388
388
|
/**
|
|
389
389
|
* fill the given shape
|
|
390
390
|
* @name fill
|
|
391
|
-
* @
|
|
391
|
+
* @memberof me.Renderer.prototype
|
|
392
392
|
* @function
|
|
393
393
|
* @param {me.Rect|me.Polygon|me.Line|me.Ellipse} shape a shape object to fill
|
|
394
394
|
*/
|
|
@@ -401,7 +401,7 @@ class Renderer {
|
|
|
401
401
|
* So, if the renderable is larger than the mask, only the intersecting part of the renderable will be visible.
|
|
402
402
|
* Mask are not preserved through renderer context save and restore.
|
|
403
403
|
* @name setMask
|
|
404
|
-
* @
|
|
404
|
+
* @memberof me.Renderer.prototype
|
|
405
405
|
* @function
|
|
406
406
|
* @param {me.Rect|me.Polygon|me.Line|me.Ellipse} [mask] the shape defining the mask to be applied
|
|
407
407
|
*/
|
|
@@ -412,7 +412,7 @@ class Renderer {
|
|
|
412
412
|
* disable (remove) the rendering mask set through setMask.
|
|
413
413
|
* @name clearMask
|
|
414
414
|
* @see me.Renderer#setMask
|
|
415
|
-
* @
|
|
415
|
+
* @memberof me.Renderer.prototype
|
|
416
416
|
* @function
|
|
417
417
|
*/
|
|
418
418
|
clearMask() {}
|
|
@@ -420,10 +420,10 @@ class Renderer {
|
|
|
420
420
|
/**
|
|
421
421
|
* set a coloring tint for sprite based renderables
|
|
422
422
|
* @name setTint
|
|
423
|
-
* @
|
|
423
|
+
* @memberof me.Renderer.prototype
|
|
424
424
|
* @function
|
|
425
425
|
* @param {me.Color} tint the tint color
|
|
426
|
-
* @param {
|
|
426
|
+
* @param {number} [alpha] an alpha value to be applied to the tint
|
|
427
427
|
*/
|
|
428
428
|
setTint(tint, alpha = tint.alpha) {
|
|
429
429
|
// global tint color
|
|
@@ -435,7 +435,7 @@ class Renderer {
|
|
|
435
435
|
* clear the rendering tint set through setTint.
|
|
436
436
|
* @name clearTint
|
|
437
437
|
* @see me.Renderer#setTint
|
|
438
|
-
* @
|
|
438
|
+
* @memberof me.Renderer.prototype
|
|
439
439
|
* @function
|
|
440
440
|
*/
|
|
441
441
|
clearTint() {
|
package/src/video/texture.js
CHANGED
|
@@ -8,62 +8,60 @@ import loader from "./../loader/loader.js";
|
|
|
8
8
|
import { ETA } from "./../math/math.js";
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
* - [ShoeBox]{@link http://renderhjs.net/shoebox/} : through JSON export using the
|
|
15
|
-
* melonJS setting [file]{@link https://github.com/melonjs/melonJS/raw/master/media/shoebox_JSON_export.sbx} <br>
|
|
16
|
-
* - [Free Texture Packer]{@link http://free-tex-packer.com/app/} : through JSON export (standard and multipack texture atlas) <br>
|
|
17
|
-
* - Standard (fixed cell size) spritesheet : through a {framewidth:xx, frameheight:xx, anchorPoint:me.Vector2d} object
|
|
18
|
-
* @class Texture
|
|
19
|
-
* @memberOf me.Renderer
|
|
20
|
-
* @constructor
|
|
21
|
-
* @param {Object|Object[]} atlas atlas information. See {@link me.loader.getJSON}
|
|
22
|
-
* @param {HTMLImageElement|HTMLCanvasElement|String|HTMLImageElement[]|HTMLCanvasElement[]|String[]} [source=atlas.meta.image] Image source
|
|
23
|
-
* @param {Boolean} [cached=false] Use true to skip caching this Texture
|
|
24
|
-
* @example
|
|
25
|
-
* // create a texture atlas from a JSON Object
|
|
26
|
-
* game.texture = new me.video.renderer.Texture(
|
|
27
|
-
* me.loader.getJSON("texture")
|
|
28
|
-
* );
|
|
29
|
-
*
|
|
30
|
-
* // create a texture atlas from a multipack JSON Object
|
|
31
|
-
* game.texture = new me.video.renderer.Texture([
|
|
32
|
-
* me.loader.getJSON("texture-0"),
|
|
33
|
-
* me.loader.getJSON("texture-1"),
|
|
34
|
-
* me.loader.getJSON("texture-2")
|
|
35
|
-
* ]);
|
|
36
|
-
*
|
|
37
|
-
* // create a texture atlas for a spritesheet with an anchorPoint in the center of each frame
|
|
38
|
-
* game.texture = new me.video.renderer.Texture(
|
|
39
|
-
* {
|
|
40
|
-
* framewidth : 32,
|
|
41
|
-
* frameheight : 32,
|
|
42
|
-
* anchorPoint : new me.Vector2d(0.5, 0.5)
|
|
43
|
-
* },
|
|
44
|
-
* me.loader.getImage("spritesheet")
|
|
45
|
-
* );
|
|
46
|
-
*/
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* create a simple 1 frame texture atlas based on the given parameters
|
|
50
|
-
* @ignore
|
|
51
|
-
*/
|
|
11
|
+
* create a simple 1 frame texture atlas based on the given parameters
|
|
12
|
+
* @ignore
|
|
13
|
+
*/
|
|
52
14
|
export function createAtlas(width, height, name = "default", repeat = "no-repeat") {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
15
|
+
return {
|
|
16
|
+
"meta" : {
|
|
17
|
+
"app" : "melonJS",
|
|
18
|
+
"size" : { "w" : width, "h" : height },
|
|
19
|
+
"repeat" : repeat,
|
|
20
|
+
"image" : "default"
|
|
21
|
+
},
|
|
22
|
+
"frames" : [{
|
|
23
|
+
"filename" : name,
|
|
24
|
+
"frame" : { "x" : 0, "y" : 0, "w" : width, "h" : height }
|
|
25
|
+
}]
|
|
26
|
+
};
|
|
65
27
|
}
|
|
66
28
|
|
|
29
|
+
/**
|
|
30
|
+
* @classdesc
|
|
31
|
+
* A Texture atlas object, currently supports : <br>
|
|
32
|
+
* - [TexturePacker]{@link http://www.codeandweb.com/texturepacker/} : through JSON export (standard and multipack texture atlas) <br>
|
|
33
|
+
* - [ShoeBox]{@link http://renderhjs.net/shoebox/} : through JSON export using the
|
|
34
|
+
* melonJS setting [file]{@link https://github.com/melonjs/melonJS/raw/master/media/shoebox_JSON_export.sbx} <br>
|
|
35
|
+
* - [Free Texture Packer]{@link http://free-tex-packer.com/app/} : through JSON export (standard and multipack texture atlas) <br>
|
|
36
|
+
* - Standard (fixed cell size) spritesheet : through a {framewidth:xx, frameheight:xx, anchorPoint:me.Vector2d} object
|
|
37
|
+
* @class Texture
|
|
38
|
+
* @memberof me.Renderer
|
|
39
|
+
* @param {object|object[]} atlases atlas information. See {@link me.loader.getJSON}
|
|
40
|
+
* @param {HTMLImageElement|HTMLCanvasElement|string|HTMLImageElement[]|HTMLCanvasElement[]|string[]} [src=atlas.meta.image] Image source
|
|
41
|
+
* @param {boolean} [cache=false] Use true to skip caching this Texture
|
|
42
|
+
* @example
|
|
43
|
+
* // create a texture atlas from a JSON Object
|
|
44
|
+
* game.texture = new me.video.renderer.Texture(
|
|
45
|
+
* me.loader.getJSON("texture")
|
|
46
|
+
* );
|
|
47
|
+
*
|
|
48
|
+
* // create a texture atlas from a multipack JSON Object
|
|
49
|
+
* game.texture = new me.video.renderer.Texture([
|
|
50
|
+
* me.loader.getJSON("texture-0"),
|
|
51
|
+
* me.loader.getJSON("texture-1"),
|
|
52
|
+
* me.loader.getJSON("texture-2")
|
|
53
|
+
* ]);
|
|
54
|
+
*
|
|
55
|
+
* // create a texture atlas for a spritesheet with an anchorPoint in the center of each frame
|
|
56
|
+
* game.texture = new me.video.renderer.Texture(
|
|
57
|
+
* {
|
|
58
|
+
* framewidth : 32,
|
|
59
|
+
* frameheight : 32,
|
|
60
|
+
* anchorPoint : new me.Vector2d(0.5, 0.5)
|
|
61
|
+
* },
|
|
62
|
+
* me.loader.getImage("spritesheet")
|
|
63
|
+
* );
|
|
64
|
+
*/
|
|
67
65
|
export class Texture {
|
|
68
66
|
|
|
69
67
|
constructor (atlases, src, cache) {
|
|
@@ -75,14 +73,14 @@ export class Texture {
|
|
|
75
73
|
|
|
76
74
|
/**
|
|
77
75
|
* the texture source(s) itself
|
|
78
|
-
* @type Map
|
|
76
|
+
* @type {Map}
|
|
79
77
|
* @ignore
|
|
80
78
|
*/
|
|
81
79
|
this.sources = new Map();
|
|
82
80
|
|
|
83
81
|
/**
|
|
84
82
|
* the atlas dictionnaries
|
|
85
|
-
* @type Map
|
|
83
|
+
* @type {Map}
|
|
86
84
|
* @ignore
|
|
87
85
|
*/
|
|
88
86
|
this.atlases = new Map();
|
|
@@ -325,14 +323,14 @@ export class Texture {
|
|
|
325
323
|
/**
|
|
326
324
|
* return the default or specified atlas dictionnary
|
|
327
325
|
* @name getAtlas
|
|
328
|
-
* @
|
|
326
|
+
* @memberof me.Renderer.Texture
|
|
329
327
|
* @function
|
|
330
|
-
* @param {
|
|
331
|
-
* @
|
|
328
|
+
* @param {string} [name] atlas name in case of multipack textures
|
|
329
|
+
* @returns {object}
|
|
332
330
|
*/
|
|
333
|
-
getAtlas(
|
|
334
|
-
if (typeof
|
|
335
|
-
return this.atlases.get(
|
|
331
|
+
getAtlas(name) {
|
|
332
|
+
if (typeof name === "string") {
|
|
333
|
+
return this.atlases.get(name);
|
|
336
334
|
} else {
|
|
337
335
|
return this.atlases.values().next().value;
|
|
338
336
|
}
|
|
@@ -341,9 +339,9 @@ export class Texture {
|
|
|
341
339
|
/**
|
|
342
340
|
* return the format of the atlas dictionnary
|
|
343
341
|
* @name getFormat
|
|
344
|
-
* @
|
|
342
|
+
* @memberof me.Renderer.Texture
|
|
345
343
|
* @function
|
|
346
|
-
* @
|
|
344
|
+
* @returns {string} will return "texturepacker", or "ShoeBox", or "melonJS", or "Spritesheet (fixed cell size)"
|
|
347
345
|
*/
|
|
348
346
|
getFormat() {
|
|
349
347
|
return this.format;
|
|
@@ -352,10 +350,10 @@ export class Texture {
|
|
|
352
350
|
/**
|
|
353
351
|
* return the source texture for the given region (or default one if none specified)
|
|
354
352
|
* @name getTexture
|
|
355
|
-
* @
|
|
353
|
+
* @memberof me.Renderer.Texture
|
|
356
354
|
* @function
|
|
357
|
-
* @param {
|
|
358
|
-
* @
|
|
355
|
+
* @param {object} [region] region name in case of multipack textures
|
|
356
|
+
* @returns {HTMLImageElement|HTMLCanvasElement}
|
|
359
357
|
*/
|
|
360
358
|
getTexture(region) {
|
|
361
359
|
if ((typeof region === "object") && (typeof region.texture === "string")) {
|
|
@@ -368,11 +366,11 @@ export class Texture {
|
|
|
368
366
|
/**
|
|
369
367
|
* return a normalized region (or frame) information for the specified sprite name
|
|
370
368
|
* @name getRegion
|
|
371
|
-
* @
|
|
369
|
+
* @memberof me.Renderer.Texture
|
|
372
370
|
* @function
|
|
373
|
-
* @param {
|
|
374
|
-
* @param {
|
|
375
|
-
* @
|
|
371
|
+
* @param {string} name name of the sprite
|
|
372
|
+
* @param {string} [atlas] name of a specific atlas where to search for the region
|
|
373
|
+
* @returns {object}
|
|
376
374
|
*/
|
|
377
375
|
getRegion(name, atlas) {
|
|
378
376
|
var region;
|
|
@@ -393,10 +391,10 @@ export class Texture {
|
|
|
393
391
|
/**
|
|
394
392
|
* return the uvs mapping for the given region
|
|
395
393
|
* @name getUVs
|
|
396
|
-
* @
|
|
394
|
+
* @memberof me.Renderer.Texture
|
|
397
395
|
* @function
|
|
398
|
-
* @param {
|
|
399
|
-
* @
|
|
396
|
+
* @param {object} name region (or frame) name
|
|
397
|
+
* @returns {Float32Array} region Uvs
|
|
400
398
|
*/
|
|
401
399
|
getUVs(name) {
|
|
402
400
|
// Get the source texture region
|
|
@@ -417,12 +415,12 @@ export class Texture {
|
|
|
417
415
|
/**
|
|
418
416
|
* Create a sprite object using the first region found using the specified name
|
|
419
417
|
* @name createSpriteFromName
|
|
420
|
-
* @
|
|
418
|
+
* @memberof me.Renderer.Texture
|
|
421
419
|
* @function
|
|
422
|
-
* @param {
|
|
423
|
-
* @param {
|
|
424
|
-
* @param {
|
|
425
|
-
* @
|
|
420
|
+
* @param {string} name name of the sprite
|
|
421
|
+
* @param {object} [settings] Additional settings passed to the {@link me.Sprite} contructor
|
|
422
|
+
* @param {boolean} [nineSlice=false] if true returns a 9-slice sprite
|
|
423
|
+
* @returns {me.Sprite|me.NineSliceSprite}
|
|
426
424
|
* @example
|
|
427
425
|
* // create a new texture object under the `game` namespace
|
|
428
426
|
* game.texture = new me.video.renderer.Texture(
|
|
@@ -460,12 +458,12 @@ export class Texture {
|
|
|
460
458
|
/**
|
|
461
459
|
* Create an animation object using the first region found using all specified names
|
|
462
460
|
* @name createAnimationFromName
|
|
463
|
-
* @
|
|
461
|
+
* @memberof me.Renderer.Texture
|
|
464
462
|
* @function
|
|
465
|
-
* @param {
|
|
463
|
+
* @param {string[]|number[]} names list of names for each sprite
|
|
466
464
|
* (when manually creating a Texture out of a spritesheet, only numeric values are authorized)
|
|
467
|
-
* @param {
|
|
468
|
-
* @
|
|
465
|
+
* @param {object} [settings] Additional settings passed to the {@link me.Sprite} contructor
|
|
466
|
+
* @returns {me.Sprite}
|
|
469
467
|
* @example
|
|
470
468
|
* // create a new texture object under the `game` namespace
|
|
471
469
|
* game.texture = new me.video.renderer.Texture(
|