melonjs 10.1.1 → 10.2.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 +6 -10
- package/dist/melonjs.js +3114 -2866
- package/dist/melonjs.min.js +3 -3
- package/dist/melonjs.module.d.ts +2588 -2498
- package/dist/melonjs.module.js +2694 -2479
- package/package.json +10 -11
- package/src/audio/audio.js +43 -43
- package/src/camera/camera2d.js +52 -74
- package/src/entity/draggable.js +18 -17
- package/src/entity/droptarget.js +19 -18
- package/src/entity/entity.js +22 -26
- package/src/game.js +3 -3
- package/src/index.js +15 -11
- package/src/input/gamepad.js +13 -13
- package/src/input/input.js +1 -1
- package/src/input/keyboard.js +14 -16
- package/src/input/pointer.js +42 -35
- package/src/input/pointerevent.js +25 -33
- package/src/lang/deprecated.js +3 -3
- package/src/level/level.js +24 -16
- package/src/level/tiled/TMXGroup.js +6 -6
- package/src/level/tiled/TMXLayer.js +31 -31
- package/src/level/tiled/TMXObject.js +19 -19
- package/src/level/tiled/TMXTile.js +11 -12
- package/src/level/tiled/TMXTileMap.js +23 -21
- package/src/level/tiled/TMXTileset.js +13 -13
- package/src/level/tiled/TMXTilesetGroup.js +4 -4
- package/src/level/tiled/TMXUtils.js +13 -11
- package/src/level/tiled/renderer/TMXHexagonalRenderer.js +1 -1
- package/src/level/tiled/renderer/TMXIsometricRenderer.js +1 -1
- package/src/level/tiled/renderer/TMXRenderer.js +17 -17
- package/src/loader/loader.js +31 -27
- package/src/loader/loadingscreen.js +44 -75
- package/src/math/color.js +45 -64
- package/src/math/math.js +17 -17
- package/src/math/matrix2.js +46 -46
- package/src/math/matrix3.js +64 -64
- package/src/math/observable_vector2.js +45 -57
- package/src/math/observable_vector3.js +56 -70
- package/src/math/vector2.js +60 -59
- package/src/math/vector3.js +65 -64
- package/src/particles/emitter.js +53 -55
- package/src/particles/particle.js +1 -1
- package/src/physics/body.js +45 -51
- package/src/physics/bounds.js +36 -36
- package/src/physics/collision.js +15 -16
- package/src/physics/detector.js +10 -11
- package/src/physics/quadtree.js +18 -16
- package/src/physics/sat.js +17 -17
- package/src/physics/world.js +12 -10
- package/src/plugin/plugin.js +6 -6
- package/src/renderable/GUI.js +13 -18
- package/src/renderable/collectable.js +3 -3
- package/src/renderable/colorlayer.js +4 -4
- package/src/renderable/container.js +64 -46
- package/src/renderable/imagelayer.js +30 -31
- package/src/renderable/nineslicesprite.js +158 -69
- package/src/renderable/renderable.js +68 -67
- package/src/renderable/sprite.js +57 -43
- package/src/renderable/trigger.js +14 -15
- package/src/shapes/ellipse.js +27 -26
- package/src/shapes/line.js +8 -7
- package/src/shapes/poly.js +33 -31
- package/src/shapes/rectangle.js +50 -96
- package/src/state/stage.js +8 -8
- package/src/state/state.js +56 -56
- package/src/system/device.js +97 -84
- package/src/system/event.js +72 -72
- package/src/system/pooling.js +14 -14
- package/src/system/save.js +6 -3
- package/src/system/timer.js +20 -20
- package/src/text/bitmaptext.js +27 -33
- package/src/text/bitmaptextdata.js +9 -9
- package/src/text/text.js +118 -59
- package/src/tweens/easing.js +4 -4
- package/src/tweens/interpolation.js +4 -4
- package/src/tweens/tween.js +37 -27
- package/src/utils/agent.js +9 -8
- package/src/utils/array.js +4 -4
- package/src/utils/file.js +4 -4
- package/src/utils/function.js +5 -5
- package/src/utils/string.js +12 -12
- package/src/utils/utils.js +19 -19
- package/src/video/canvas/canvas_renderer.js +90 -90
- package/src/video/renderer.js +40 -39
- package/src/video/texture.js +85 -76
- package/src/video/texture_cache.js +11 -0
- package/src/video/video.js +31 -31
- package/src/video/webgl/buffer/vertex.js +9 -1
- package/src/video/webgl/glshader.js +20 -20
- package/src/video/webgl/webgl_compositor.js +47 -46
- package/src/video/webgl/webgl_renderer.js +104 -104
package/src/video/texture.js
CHANGED
|
@@ -8,62 +8,61 @@ 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
|
+
* @constructor
|
|
40
|
+
* @param {object|object[]} atlases atlas information. See {@link me.loader.getJSON}
|
|
41
|
+
* @param {HTMLImageElement|HTMLCanvasElement|string|HTMLImageElement[]|HTMLCanvasElement[]|string[]} [src=atlas.meta.image] Image source
|
|
42
|
+
* @param {boolean} [cache=false] Use true to skip caching this Texture
|
|
43
|
+
* @example
|
|
44
|
+
* // create a texture atlas from a JSON Object
|
|
45
|
+
* game.texture = new me.video.renderer.Texture(
|
|
46
|
+
* me.loader.getJSON("texture")
|
|
47
|
+
* );
|
|
48
|
+
*
|
|
49
|
+
* // create a texture atlas from a multipack JSON Object
|
|
50
|
+
* game.texture = new me.video.renderer.Texture([
|
|
51
|
+
* me.loader.getJSON("texture-0"),
|
|
52
|
+
* me.loader.getJSON("texture-1"),
|
|
53
|
+
* me.loader.getJSON("texture-2")
|
|
54
|
+
* ]);
|
|
55
|
+
*
|
|
56
|
+
* // create a texture atlas for a spritesheet with an anchorPoint in the center of each frame
|
|
57
|
+
* game.texture = new me.video.renderer.Texture(
|
|
58
|
+
* {
|
|
59
|
+
* framewidth : 32,
|
|
60
|
+
* frameheight : 32,
|
|
61
|
+
* anchorPoint : new me.Vector2d(0.5, 0.5)
|
|
62
|
+
* },
|
|
63
|
+
* me.loader.getImage("spritesheet")
|
|
64
|
+
* );
|
|
65
|
+
*/
|
|
67
66
|
export class Texture {
|
|
68
67
|
|
|
69
68
|
constructor (atlases, src, cache) {
|
|
@@ -75,14 +74,14 @@ export class Texture {
|
|
|
75
74
|
|
|
76
75
|
/**
|
|
77
76
|
* the texture source(s) itself
|
|
78
|
-
* @type Map
|
|
77
|
+
* @type {Map}
|
|
79
78
|
* @ignore
|
|
80
79
|
*/
|
|
81
80
|
this.sources = new Map();
|
|
82
81
|
|
|
83
82
|
/**
|
|
84
83
|
* the atlas dictionnaries
|
|
85
|
-
* @type Map
|
|
84
|
+
* @type {Map}
|
|
86
85
|
* @ignore
|
|
87
86
|
*/
|
|
88
87
|
this.atlases = new Map();
|
|
@@ -327,12 +326,12 @@ export class Texture {
|
|
|
327
326
|
* @name getAtlas
|
|
328
327
|
* @memberOf me.Renderer.Texture
|
|
329
328
|
* @function
|
|
330
|
-
* @param {
|
|
331
|
-
* @
|
|
329
|
+
* @param {string} [name] atlas name in case of multipack textures
|
|
330
|
+
* @returns {object}
|
|
332
331
|
*/
|
|
333
|
-
getAtlas(
|
|
334
|
-
if (typeof
|
|
335
|
-
return this.atlases.get(
|
|
332
|
+
getAtlas(name) {
|
|
333
|
+
if (typeof name === "string") {
|
|
334
|
+
return this.atlases.get(name);
|
|
336
335
|
} else {
|
|
337
336
|
return this.atlases.values().next().value;
|
|
338
337
|
}
|
|
@@ -343,7 +342,7 @@ export class Texture {
|
|
|
343
342
|
* @name getFormat
|
|
344
343
|
* @memberOf me.Renderer.Texture
|
|
345
344
|
* @function
|
|
346
|
-
* @
|
|
345
|
+
* @returns {string} will return "texturepacker", or "ShoeBox", or "melonJS", or "Spritesheet (fixed cell size)"
|
|
347
346
|
*/
|
|
348
347
|
getFormat() {
|
|
349
348
|
return this.format;
|
|
@@ -354,8 +353,8 @@ export class Texture {
|
|
|
354
353
|
* @name getTexture
|
|
355
354
|
* @memberOf me.Renderer.Texture
|
|
356
355
|
* @function
|
|
357
|
-
* @param {
|
|
358
|
-
* @
|
|
356
|
+
* @param {object} [region] region name in case of multipack textures
|
|
357
|
+
* @returns {HTMLImageElement|HTMLCanvasElement}
|
|
359
358
|
*/
|
|
360
359
|
getTexture(region) {
|
|
361
360
|
if ((typeof region === "object") && (typeof region.texture === "string")) {
|
|
@@ -370,9 +369,9 @@ export class Texture {
|
|
|
370
369
|
* @name getRegion
|
|
371
370
|
* @memberOf me.Renderer.Texture
|
|
372
371
|
* @function
|
|
373
|
-
* @param {
|
|
374
|
-
* @param {
|
|
375
|
-
* @
|
|
372
|
+
* @param {string} name name of the sprite
|
|
373
|
+
* @param {string} [atlas] name of a specific atlas where to search for the region
|
|
374
|
+
* @returns {object}
|
|
376
375
|
*/
|
|
377
376
|
getRegion(name, atlas) {
|
|
378
377
|
var region;
|
|
@@ -395,8 +394,8 @@ export class Texture {
|
|
|
395
394
|
* @name getUVs
|
|
396
395
|
* @memberOf me.Renderer.Texture
|
|
397
396
|
* @function
|
|
398
|
-
* @param {
|
|
399
|
-
* @
|
|
397
|
+
* @param {object} name region (or frame) name
|
|
398
|
+
* @returns {Float32Array} region Uvs
|
|
400
399
|
*/
|
|
401
400
|
getUVs(name) {
|
|
402
401
|
// Get the source texture region
|
|
@@ -419,9 +418,10 @@ export class Texture {
|
|
|
419
418
|
* @name createSpriteFromName
|
|
420
419
|
* @memberOf me.Renderer.Texture
|
|
421
420
|
* @function
|
|
422
|
-
* @param {
|
|
423
|
-
* @param {
|
|
424
|
-
* @
|
|
421
|
+
* @param {string} name name of the sprite
|
|
422
|
+
* @param {object} [settings] Additional settings passed to the {@link me.Sprite} contructor
|
|
423
|
+
* @param {boolean} [nineSlice=false] if true returns a 9-slice sprite
|
|
424
|
+
* @returns {me.Sprite|me.NineSliceSprite}
|
|
425
425
|
* @example
|
|
426
426
|
* // create a new texture object under the `game` namespace
|
|
427
427
|
* game.texture = new me.video.renderer.Texture(
|
|
@@ -434,11 +434,20 @@ export class Texture {
|
|
|
434
434
|
* var sprite = game.texture.createSpriteFromName("coin.png");
|
|
435
435
|
* // set the renderable position to bottom center
|
|
436
436
|
* sprite.anchorPoint.set(0.5, 1.0);
|
|
437
|
+
* ...
|
|
438
|
+
* ...
|
|
439
|
+
* // create a 9-slice sprite
|
|
440
|
+
* var dialogPanel = game.texture.createSpriteFromName(
|
|
441
|
+
* "rpg_dialo.png",
|
|
442
|
+
* // width & height are mandatory for 9-slice sprites
|
|
443
|
+
* { width: this.width, height: this.height },
|
|
444
|
+
* true
|
|
445
|
+
* );
|
|
437
446
|
*/
|
|
438
|
-
createSpriteFromName(name, settings) {
|
|
447
|
+
createSpriteFromName(name, settings, nineSlice = false) {
|
|
439
448
|
// instantiate a new sprite object
|
|
440
449
|
return pool.pull(
|
|
441
|
-
"me.Sprite",
|
|
450
|
+
nineSlice === true ? "me.NineSliceSprite" : "me.Sprite",
|
|
442
451
|
0, 0,
|
|
443
452
|
Object.assign({
|
|
444
453
|
image: this,
|
|
@@ -452,10 +461,10 @@ export class Texture {
|
|
|
452
461
|
* @name createAnimationFromName
|
|
453
462
|
* @memberOf me.Renderer.Texture
|
|
454
463
|
* @function
|
|
455
|
-
* @param {
|
|
464
|
+
* @param {string[]|number[]} names list of names for each sprite
|
|
456
465
|
* (when manually creating a Texture out of a spritesheet, only numeric values are authorized)
|
|
457
|
-
* @param {
|
|
458
|
-
* @
|
|
466
|
+
* @param {object} [settings] Additional settings passed to the {@link me.Sprite} contructor
|
|
467
|
+
* @returns {me.Sprite}
|
|
459
468
|
* @example
|
|
460
469
|
* // create a new texture object under the `game` namespace
|
|
461
470
|
* game.texture = new me.video.renderer.Texture(
|
|
@@ -57,6 +57,17 @@ class TextureCache {
|
|
|
57
57
|
return this.cache.get(image);
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
+
/**
|
|
61
|
+
* @ignore
|
|
62
|
+
*/
|
|
63
|
+
remove(image) {
|
|
64
|
+
if (!this.cache.has(image)) {
|
|
65
|
+
if (this.cache.remove(image) === true) {
|
|
66
|
+
this.length--;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
60
71
|
/**
|
|
61
72
|
* @ignore
|
|
62
73
|
*/
|
package/src/video/video.js
CHANGED
|
@@ -192,20 +192,20 @@ export let renderer = null;
|
|
|
192
192
|
* - <i><b>`stretch`</b></i> : Canvas is resized to fit; content is scaled to screen aspect ratio
|
|
193
193
|
* <center><img src="images/scale-stretch.png"/></center><br>
|
|
194
194
|
* @function me.video.init
|
|
195
|
-
* @param {
|
|
196
|
-
* @param {
|
|
197
|
-
* @param {
|
|
198
|
-
* @param {
|
|
199
|
-
* @param {
|
|
200
|
-
* @param {
|
|
201
|
-
* @param {
|
|
202
|
-
* @param {
|
|
203
|
-
* @param {
|
|
204
|
-
* @param {
|
|
205
|
-
* @param {
|
|
206
|
-
* @param {
|
|
207
|
-
* @param {
|
|
208
|
-
* @
|
|
195
|
+
* @param {number} width The width of the canvas viewport
|
|
196
|
+
* @param {number} height The height of the canvas viewport
|
|
197
|
+
* @param {object} [options] The optional video/renderer parameters.<br> (see Renderer(s) documentation for further specific options)
|
|
198
|
+
* @param {string|HTMLElement} [options.parent=document.body] the DOM parent element to hold the canvas in the HTML file
|
|
199
|
+
* @param {number} [options.renderer=me.video.AUTO] renderer to use (me.video.CANVAS, me.video.WEBGL, me.video.AUTO)
|
|
200
|
+
* @param {boolean} [options.doubleBuffering=false] enable/disable double buffering
|
|
201
|
+
* @param {number|string} [options.scale=1.0] enable scaling of the canvas ('auto' for automatic scaling)
|
|
202
|
+
* @param {string} [options.scaleMethod="fit"] screen scaling modes ('fit','fill-min','fill-max','flex','flex-width','flex-height','stretch')
|
|
203
|
+
* @param {boolean} [options.preferWebGL1=false] if true the renderer will only use WebGL 1
|
|
204
|
+
* @param {string} [options.powerPreference="default"] a hint to the user agent indicating what configuration of GPU is suitable for the WebGL context ("default", "high-performance", "low-power"). To be noted that Safari and Chrome (since version 80) both default to "low-power" to save battery life and improve the user experience on these dual-GPU machines.
|
|
205
|
+
* @param {boolean} [options.transparent=false] whether to allow transparent pixels in the front buffer (screen).
|
|
206
|
+
* @param {boolean} [options.antiAlias=false] whether to enable or not video scaling interpolation
|
|
207
|
+
* @param {boolean} [options.consoleHeader=true] whether to display melonJS version and basic device information in the console
|
|
208
|
+
* @returns {boolean} false if initialization failed (canvas not supported)
|
|
209
209
|
* @example
|
|
210
210
|
* // init the video with a 640x480 canvas
|
|
211
211
|
* me.video.init(640, 480, {
|
|
@@ -216,7 +216,7 @@ export let renderer = null;
|
|
|
216
216
|
* doubleBuffering : true
|
|
217
217
|
* });
|
|
218
218
|
*/
|
|
219
|
-
export function init(
|
|
219
|
+
export function init(width, height, options) {
|
|
220
220
|
|
|
221
221
|
// ensure melonjs has been properly initialized
|
|
222
222
|
if (!initialized) {
|
|
@@ -227,8 +227,8 @@ export function init(game_width, game_height, options) {
|
|
|
227
227
|
settings = Object.assign(settings, options || {});
|
|
228
228
|
|
|
229
229
|
// sanitize potential given parameters
|
|
230
|
-
settings.width =
|
|
231
|
-
settings.height =
|
|
230
|
+
settings.width = width;
|
|
231
|
+
settings.height = height;
|
|
232
232
|
settings.doubleBuffering = !!(settings.doubleBuffering);
|
|
233
233
|
settings.transparent = !!(settings.transparent);
|
|
234
234
|
settings.antiAlias = !!(settings.antiAlias);
|
|
@@ -268,13 +268,13 @@ export function init(game_width, game_height, options) {
|
|
|
268
268
|
}
|
|
269
269
|
|
|
270
270
|
// hold the requested video size ratio
|
|
271
|
-
designRatio =
|
|
272
|
-
designWidth =
|
|
273
|
-
designHeight =
|
|
271
|
+
designRatio = width / height;
|
|
272
|
+
designWidth = width;
|
|
273
|
+
designHeight = height;
|
|
274
274
|
|
|
275
275
|
// default scaled size value
|
|
276
|
-
settings.zoomX =
|
|
277
|
-
settings.zoomY =
|
|
276
|
+
settings.zoomX = width * scaleRatio.x;
|
|
277
|
+
settings.zoomY = width * scaleRatio.y;
|
|
278
278
|
|
|
279
279
|
//add a channel for the onresize/onorientationchange event
|
|
280
280
|
window.addEventListener(
|
|
@@ -367,7 +367,7 @@ export function init(game_width, game_height, options) {
|
|
|
367
367
|
device.getScreenOrientation() + " | " +
|
|
368
368
|
device.language
|
|
369
369
|
);
|
|
370
|
-
console.log( "resolution: " + "requested " +
|
|
370
|
+
console.log( "resolution: " + "requested " + width + "x" + height +
|
|
371
371
|
", got " + renderer.getWidth() + "x" + renderer.getHeight()
|
|
372
372
|
);
|
|
373
373
|
}
|
|
@@ -381,12 +381,12 @@ export function init(game_width, game_height, options) {
|
|
|
381
381
|
/**
|
|
382
382
|
* Create and return a new Canvas element
|
|
383
383
|
* @function me.video.createCanvas
|
|
384
|
-
* @param {
|
|
385
|
-
* @param {
|
|
386
|
-
* @param {
|
|
387
|
-
* @
|
|
384
|
+
* @param {number} width width
|
|
385
|
+
* @param {number} height height
|
|
386
|
+
* @param {boolean} [offscreen=false] will returns an OffscreenCanvas if supported
|
|
387
|
+
* @returns {HTMLCanvasElement|OffscreenCanvas}
|
|
388
388
|
*/
|
|
389
|
-
export function createCanvas(width, height, offscreen) {
|
|
389
|
+
export function createCanvas(width, height, offscreen = false) {
|
|
390
390
|
var _canvas;
|
|
391
391
|
|
|
392
392
|
if (width === 0 || height === 0) {
|
|
@@ -413,7 +413,7 @@ export function createCanvas(width, height, offscreen) {
|
|
|
413
413
|
/**
|
|
414
414
|
* return a reference to the parent DOM element holding the main canvas
|
|
415
415
|
* @function me.video.getParent
|
|
416
|
-
* @
|
|
416
|
+
* @returns {HTMLElement}
|
|
417
417
|
*/
|
|
418
418
|
export function getParent() {
|
|
419
419
|
return parent;
|
|
@@ -425,8 +425,8 @@ export function getParent() {
|
|
|
425
425
|
* Only use this if you are not using the automatic scaling feature.
|
|
426
426
|
* @function me.video.scale
|
|
427
427
|
* @see me.video.init
|
|
428
|
-
* @param {
|
|
429
|
-
* @param {
|
|
428
|
+
* @param {number} x x scaling multiplier
|
|
429
|
+
* @param {number} y y scaling multiplier
|
|
430
430
|
*/
|
|
431
431
|
export function scale(x, y) {
|
|
432
432
|
var canvas = renderer.getScreenCanvas();
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @classdesc
|
|
3
3
|
* a Vertex Buffer object
|
|
4
4
|
* @class VertexArrayBuffer
|
|
5
|
-
* @
|
|
5
|
+
* @ignore
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
class VertexArrayBuffer {
|
|
@@ -29,6 +29,7 @@ class VertexArrayBuffer {
|
|
|
29
29
|
|
|
30
30
|
/**
|
|
31
31
|
* clear the vertex array buffer
|
|
32
|
+
* @ignore
|
|
32
33
|
*/
|
|
33
34
|
clear() {
|
|
34
35
|
this.vertexCount = 0;
|
|
@@ -37,6 +38,7 @@ class VertexArrayBuffer {
|
|
|
37
38
|
|
|
38
39
|
/**
|
|
39
40
|
* return true if full
|
|
41
|
+
* @ignore
|
|
40
42
|
*/
|
|
41
43
|
isFull(vertex = 0) {
|
|
42
44
|
return (this.vertexCount + vertex >= this.maxVertex);
|
|
@@ -44,6 +46,7 @@ class VertexArrayBuffer {
|
|
|
44
46
|
|
|
45
47
|
/**
|
|
46
48
|
* resize the vertex buffer, retaining its original contents
|
|
49
|
+
* @ignore
|
|
47
50
|
*/
|
|
48
51
|
resize() {
|
|
49
52
|
// double the vertex size
|
|
@@ -64,6 +67,7 @@ class VertexArrayBuffer {
|
|
|
64
67
|
|
|
65
68
|
/**
|
|
66
69
|
* push a new vertex to the buffer
|
|
70
|
+
* @ignore
|
|
67
71
|
*/
|
|
68
72
|
push(x, y, u, v, tint) {
|
|
69
73
|
var offset = this.vertexCount * this.vertexSize;
|
|
@@ -91,6 +95,7 @@ class VertexArrayBuffer {
|
|
|
91
95
|
|
|
92
96
|
/**
|
|
93
97
|
* return a reference to the data in Float32 format
|
|
98
|
+
* @ignore
|
|
94
99
|
*/
|
|
95
100
|
toFloat32(begin, end) {
|
|
96
101
|
if (typeof end !== "undefined") {
|
|
@@ -102,6 +107,7 @@ class VertexArrayBuffer {
|
|
|
102
107
|
|
|
103
108
|
/**
|
|
104
109
|
* return a reference to the data in Uint32 format
|
|
110
|
+
* @ignore
|
|
105
111
|
*/
|
|
106
112
|
toUint32(begin, end) {
|
|
107
113
|
if (typeof end !== "undefined") {
|
|
@@ -113,6 +119,7 @@ class VertexArrayBuffer {
|
|
|
113
119
|
|
|
114
120
|
/**
|
|
115
121
|
* return the size of the vertex in vertex
|
|
122
|
+
* @ignore
|
|
116
123
|
*/
|
|
117
124
|
length() {
|
|
118
125
|
return this.vertexCount;
|
|
@@ -120,6 +127,7 @@ class VertexArrayBuffer {
|
|
|
120
127
|
|
|
121
128
|
/**
|
|
122
129
|
* return true if empty
|
|
130
|
+
* @ignore
|
|
123
131
|
*/
|
|
124
132
|
isEmpty() {
|
|
125
133
|
return this.vertexCount === 0;
|
|
@@ -2,7 +2,7 @@ import * as event from "./../../system/event.js";
|
|
|
2
2
|
import device from "./../../system/device.js";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* @
|
|
5
|
+
* @ignore
|
|
6
6
|
*/
|
|
7
7
|
function extractUniforms(gl, shader) {
|
|
8
8
|
var uniforms = {},
|
|
@@ -46,9 +46,9 @@ function extractUniforms(gl, shader) {
|
|
|
46
46
|
}
|
|
47
47
|
else {
|
|
48
48
|
/**
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
* A generic setter for uniform vectors
|
|
50
|
+
* @ignore
|
|
51
|
+
*/
|
|
52
52
|
return function (val) {
|
|
53
53
|
var fnv = fn;
|
|
54
54
|
if (val.length && fn.substr(-1) !== "v") {
|
|
@@ -66,7 +66,7 @@ function extractUniforms(gl, shader) {
|
|
|
66
66
|
};
|
|
67
67
|
|
|
68
68
|
/**
|
|
69
|
-
* @
|
|
69
|
+
* @ignore
|
|
70
70
|
*/
|
|
71
71
|
function extractAttributes(gl, shader) {
|
|
72
72
|
var attributes = {},
|
|
@@ -83,7 +83,7 @@ function extractAttributes(gl, shader) {
|
|
|
83
83
|
};
|
|
84
84
|
|
|
85
85
|
/**
|
|
86
|
-
* @
|
|
86
|
+
* @ignore
|
|
87
87
|
*/
|
|
88
88
|
function compileShader(gl, type, source) {
|
|
89
89
|
var shader = gl.createShader(type);
|
|
@@ -99,7 +99,7 @@ function compileShader(gl, type, source) {
|
|
|
99
99
|
|
|
100
100
|
/**
|
|
101
101
|
* Compile GLSL into a shader object
|
|
102
|
-
* @
|
|
102
|
+
* @ignore
|
|
103
103
|
*/
|
|
104
104
|
function compileProgram(gl, vertex, fragment, attributes) {
|
|
105
105
|
var vertShader = compileShader(gl, gl.VERTEX_SHADER, vertex);
|
|
@@ -144,7 +144,7 @@ function compileProgram(gl, vertex, fragment, attributes) {
|
|
|
144
144
|
|
|
145
145
|
/**
|
|
146
146
|
* Hash map of GLSL data types to WebGL Uniform methods
|
|
147
|
-
* @
|
|
147
|
+
* @ignore
|
|
148
148
|
*/
|
|
149
149
|
var fnHash = {
|
|
150
150
|
"bool" : "1i",
|
|
@@ -168,7 +168,7 @@ var fnHash = {
|
|
|
168
168
|
/**
|
|
169
169
|
* set precision for the fiven shader source
|
|
170
170
|
* won't do anything if the precision is already specified
|
|
171
|
-
* @
|
|
171
|
+
* @ignore
|
|
172
172
|
*/
|
|
173
173
|
function setPrecision(src, precision) {
|
|
174
174
|
if (src.substring(0, 9) !== "precision") {
|
|
@@ -179,7 +179,7 @@ function setPrecision(src, precision) {
|
|
|
179
179
|
|
|
180
180
|
/**
|
|
181
181
|
* clean the given source from space, comments, etc...
|
|
182
|
-
* @
|
|
182
|
+
* @ignore
|
|
183
183
|
*/
|
|
184
184
|
function minify(src) {
|
|
185
185
|
// remove comments
|
|
@@ -200,9 +200,9 @@ function minify(src) {
|
|
|
200
200
|
* @class GLShader
|
|
201
201
|
* @memberOf me
|
|
202
202
|
* @param {WebGLRenderingContext} gl the current WebGL rendering context
|
|
203
|
-
* @param {
|
|
204
|
-
* @param {
|
|
205
|
-
* @param {
|
|
203
|
+
* @param {string} vertex a string containing the GLSL source code to set
|
|
204
|
+
* @param {string} fragment a string containing the GLSL source code to set
|
|
205
|
+
* @param {string} [precision=auto detected] float precision ('lowp', 'mediump' or 'highp').
|
|
206
206
|
* @constructor
|
|
207
207
|
* @see https://developer.mozilla.org/en-US/docs/Games/Techniques/3D_on_the_web/GLSL_Shaders
|
|
208
208
|
* @example
|
|
@@ -242,7 +242,7 @@ class GLShader {
|
|
|
242
242
|
/**
|
|
243
243
|
* the vertex shader source code
|
|
244
244
|
* @public
|
|
245
|
-
* @type {
|
|
245
|
+
* @type {string}
|
|
246
246
|
* @name vertex
|
|
247
247
|
* @memberOf me.GLShader
|
|
248
248
|
*/
|
|
@@ -251,7 +251,7 @@ class GLShader {
|
|
|
251
251
|
/**
|
|
252
252
|
* the fragment shader source code
|
|
253
253
|
* @public
|
|
254
|
-
* @type {
|
|
254
|
+
* @type {string}
|
|
255
255
|
* @name vertex
|
|
256
256
|
* @memberOf me.GLShader
|
|
257
257
|
*/
|
|
@@ -279,7 +279,7 @@ class GLShader {
|
|
|
279
279
|
/**
|
|
280
280
|
* the uniforms of the shader
|
|
281
281
|
* @public
|
|
282
|
-
* @type {
|
|
282
|
+
* @type {object}
|
|
283
283
|
* @name uniforms
|
|
284
284
|
* @memberOf me.GLShader
|
|
285
285
|
*/
|
|
@@ -306,8 +306,8 @@ class GLShader {
|
|
|
306
306
|
* @name getAttribLocation
|
|
307
307
|
* @memberOf me.GLShader
|
|
308
308
|
* @function
|
|
309
|
-
* @param {
|
|
310
|
-
* @
|
|
309
|
+
* @param {string} name the name of the attribute variable whose location to get.
|
|
310
|
+
* @returns {GLint} number indicating the location of the variable name if found. Returns -1 otherwise
|
|
311
311
|
*/
|
|
312
312
|
getAttribLocation(name) {
|
|
313
313
|
var attr = this.attributes[name];
|
|
@@ -323,8 +323,8 @@ class GLShader {
|
|
|
323
323
|
* @name setUniform
|
|
324
324
|
* @memberOf me.GLShader
|
|
325
325
|
* @function
|
|
326
|
-
* @param {
|
|
327
|
-
* @param {
|
|
326
|
+
* @param {string} name the uniform name
|
|
327
|
+
* @param {object|Float32Array} value the value to assign to that uniform
|
|
328
328
|
* @example
|
|
329
329
|
* myShader.setUniform("uProjectionMatrix", this.projectionMatrix);
|
|
330
330
|
*/
|