melonjs 10.12.0 → 13.0.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.
Files changed (50) hide show
  1. package/LICENSE.md +1 -1
  2. package/README.md +6 -6
  3. package/dist/melonjs.js +22651 -22529
  4. package/dist/melonjs.min.js +5 -6
  5. package/dist/melonjs.module.d.ts +195 -195
  6. package/dist/melonjs.module.js +22107 -21977
  7. package/package.json +14 -14
  8. package/src/application/application.js +231 -0
  9. package/src/audio/audio.js +13 -7
  10. package/src/camera/camera2d.js +6 -6
  11. package/src/game.js +9 -232
  12. package/src/index.js +3 -3
  13. package/src/input/keyboard.js +2 -2
  14. package/src/input/pointer.js +4 -5
  15. package/src/input/pointerevent.js +8 -8
  16. package/src/lang/deprecated.js +0 -29
  17. package/src/level/level.js +2 -2
  18. package/src/level/tiled/TMXLayer.js +2 -2
  19. package/src/level/tiled/TMXTileMap.js +3 -3
  20. package/src/loader/loader.js +64 -28
  21. package/src/loader/loadingscreen.js +28 -115
  22. package/src/loader/melonjs_logo.png +0 -0
  23. package/src/physics/body.js +27 -51
  24. package/src/physics/detector.js +3 -3
  25. package/src/physics/quadtree.js +58 -29
  26. package/src/physics/world.js +32 -3
  27. package/src/polyfill/index.js +4 -0
  28. package/src/renderable/container.js +2 -2
  29. package/src/renderable/imagelayer.js +8 -8
  30. package/src/renderable/light2d.js +40 -11
  31. package/src/renderable/trigger.js +4 -4
  32. package/src/state/stage.js +1 -1
  33. package/src/state/state.js +50 -3
  34. package/src/system/device.js +808 -1039
  35. package/src/system/dom.js +69 -0
  36. package/src/system/event.js +13 -1
  37. package/src/system/platform.js +32 -0
  38. package/src/system/save.js +23 -14
  39. package/src/system/timer.js +12 -35
  40. package/src/text/bitmaptext.js +1 -2
  41. package/src/text/text.js +10 -14
  42. package/src/text/textmetrics.js +1 -2
  43. package/src/tweens/tween.js +6 -6
  44. package/src/utils/string.js +13 -24
  45. package/src/video/canvas/canvas_renderer.js +3 -2
  46. package/src/video/renderer.js +2 -2
  47. package/src/video/texture/canvas_texture.js +36 -2
  48. package/src/video/video.js +15 -9
  49. package/src/video/webgl/glshader.js +1 -1
  50. package/src/video/webgl/webgl_renderer.js +1 -1
@@ -1,6 +1,6 @@
1
1
  import {preventDefault as preventDefaultAction} from "./input.js";
2
2
  import * as event from "./../system/event.js";
3
- import device from "./../system/device.js";
3
+ import { isMobile } from "./../system/platform.js";
4
4
 
5
5
  // corresponding actions
6
6
  var _keyStatus = {};
@@ -317,7 +317,7 @@ export const KEY = {
317
317
  */
318
318
  export function initKeyboardEvent() {
319
319
  // make sure the keyboard is enable
320
- if (keyBoardEventTarget === null && device.isMobile === false) {
320
+ if (keyBoardEventTarget === null && isMobile === false) {
321
321
  keyBoardEventTarget = globalThis;
322
322
  if (typeof keyBoardEventTarget.addEventListener === "function") {
323
323
  keyBoardEventTarget.addEventListener("keydown", keyDownEvent, false);
@@ -1,7 +1,6 @@
1
1
  import Vector2d from "./../math/vector2.js";
2
- import device from "./../system/device.js";
3
2
  import Bounds from "./../physics/bounds.js";
4
- import { viewport } from "./../game.js";
3
+ import game from "./../game.js";
5
4
  import { globalToLocal } from "./input.js";
6
5
  import { locked } from "./pointerevent.js";
7
6
 
@@ -333,7 +332,7 @@ class Pointer extends Bounds {
333
332
  this.gameScreenY = this.y = tmpVec.y;
334
333
 
335
334
  // true if not originally a pointer event
336
- this.isNormalized = !device.PointerEvent || (device.PointerEvent && !(event instanceof globalThis.PointerEvent));
335
+ this.isNormalized = (typeof globalThis.PointerEvent !== "undefined" && !(event instanceof globalThis.PointerEvent));
337
336
 
338
337
  this.locked = locked;
339
338
  this.movementX = event.movementX || 0;
@@ -361,8 +360,8 @@ class Pointer extends Bounds {
361
360
  this.type = event.type;
362
361
 
363
362
  // get the current screen to game world offset
364
- if (typeof viewport !== "undefined") {
365
- viewport.localToWorld(this.gameScreenX, this.gameScreenY, tmpVec);
363
+ if (typeof game.viewport !== "undefined") {
364
+ game.viewport.localToWorld(this.gameScreenX, this.gameScreenY, tmpVec);
366
365
  }
367
366
 
368
367
  /* Initialize the two coordinate space properties. */
@@ -6,11 +6,11 @@ import { remove } from "./../utils/array.js";
6
6
  import * as event from "./../system/event.js";
7
7
  import timer from "./../system/timer.js";
8
8
  import pool from "./../system/pooling.js";
9
- import device from "./../system/device.js";
9
+ import * as device from "./../system/device.js";
10
10
  import Pointer from "./pointer.js";
11
11
  import Rect from "./../geometries/rectangle.js";
12
12
  import Container from "./../renderable/container.js";
13
- import { world, viewport } from "./../game.js";
13
+ import game from "./../game.js";
14
14
 
15
15
  /**
16
16
  * A pool of `Pointer` objects to cache pointer/touch event coordinates.
@@ -128,14 +128,14 @@ function enablePointerEvent() {
128
128
  pointerEventTarget = renderer.getScreenCanvas();
129
129
  }
130
130
 
131
- if (device.PointerEvent) {
131
+ if (device.pointerEvent) {
132
132
  // standard Pointer Events
133
133
  activeEventList = pointerEventList;
134
134
  } else {
135
135
  // Regular Mouse events
136
136
  activeEventList = mouseEventList;
137
137
  }
138
- if (device.touch && !device.PointerEvent) {
138
+ if (device.touch && !device.pointerEvent) {
139
139
  // touch event on mobile devices
140
140
  activeEventList = activeEventList.concat(touchEventList);
141
141
  }
@@ -287,10 +287,10 @@ function dispatchEvent(normalizedEvents) {
287
287
  }
288
288
 
289
289
  // fetch valid candiates from the game world container
290
- var candidates = world.broadphase.retrieve(currentPointer, Container.prototype._sortReverseZ);
290
+ var candidates = game.world.broadphase.retrieve(currentPointer, Container.prototype._sortReverseZ);
291
291
 
292
292
  // add the main game viewport to the list of candidates
293
- candidates = candidates.concat([ viewport ]);
293
+ candidates = candidates.concat([ game.viewport ]);
294
294
 
295
295
  for (var c = candidates.length, candidate; c--, (candidate = candidates[c]);) {
296
296
  if (eventHandlers.has(candidate) && (candidate.isKinematic !== true)) {
@@ -416,7 +416,7 @@ function normalizeEvent(originalEvent) {
416
416
  var _pointer;
417
417
 
418
418
  // PointerEvent or standard Mouse event
419
- if (device.TouchEvent && originalEvent.changedTouches) {
419
+ if (device.touchEvent && originalEvent.changedTouches) {
420
420
  // iOS/Android Touch event
421
421
  for (var i = 0, l = originalEvent.changedTouches.length; i < l; i++) {
422
422
  var touchEvent = originalEvent.changedTouches[i];
@@ -557,7 +557,7 @@ export var throttlingInterval;
557
557
  export function globalToLocal(x, y, v) {
558
558
  v = v || pool.pull("Vector2d");
559
559
  var rect = device.getElementBounds(renderer.getScreenCanvas());
560
- var pixelRatio = device.devicePixelRatio;
560
+ var pixelRatio = globalThis.devicePixelRatio || 1;
561
561
  x -= rect.left + (globalThis.pageXOffset || 0);
562
562
  y -= rect.top + (globalThis.pageYOffset || 0);
563
563
  var scale = scaleRatio;
@@ -1,5 +1,3 @@
1
- import device from "./../system/device.js";
2
- import { requestPointerLock, exitPointerLock } from "./../input/input.js";
3
1
  import { TextureAtlas } from "./../video/texture/atlas.js";
4
2
  import Renderer from "./../video/renderer.js";
5
3
  import { Draggable, DropTarget } from "./../renderable/dragndrop.js";
@@ -45,35 +43,8 @@ export function warning(deprecated, replacement, version) {
45
43
  }
46
44
  };
47
45
 
48
- /**
49
- * @public
50
- * @name turnOnPointerLock
51
- * @returns {boolean} return true if the request was successfully submitted
52
- * @memberof device#
53
- * @deprecated since 10.3.0
54
- * @see input.requestPointerLock
55
- */
56
- device.turnOnPointerLock = function () {
57
- warning("device.turnOnPointerLock()", "input.requestPointerLock()", "10.3.0");
58
- return requestPointerLock();
59
- };
60
-
61
- /**
62
- * @public
63
- * @name turnOffPointerLock
64
- * @returns {boolean} return true if the request was successfully submitted
65
- * @memberof device#
66
- * @deprecated since 10.3.0
67
- * @see input.exitPointerLock
68
- */
69
- device.turnOffPointerLock = function () {
70
- warning("device.turnOffPointerLock()", "input.exitPointerLock()", "10.3.0");
71
- return exitPointerLock();
72
- };
73
-
74
46
  /**
75
47
  * Alias of {@link TextureAtlas}
76
- *
77
48
  * @public
78
49
  * @name Texture
79
50
  * @class
@@ -2,7 +2,7 @@ import utils from "./../utils/utils.js";
2
2
  import * as event from "./../system/event.js";
3
3
  import state from "./../state/state.js";
4
4
  import loader from "./../loader/loader.js";
5
- import * as game from "./../game.js";
5
+ import game from "./../game.js";
6
6
  import TMXTileMap from "./tiled/TMXTileMap.js";
7
7
 
8
8
 
@@ -125,7 +125,7 @@ var level = {
125
125
  * @param {string} levelId level id
126
126
  * @param {object} [options] additional optional parameters
127
127
  * @param {Container} [options.container=game.world] container in which to load the specified level
128
- * @param {Function} [options.onLoaded=ame.onLevelLoaded] callback for when the level is fully loaded
128
+ * @param {Function} [options.onLoaded=game.onLevelLoaded] callback for when the level is fully loaded
129
129
  * @param {boolean} [options.flatten=game.mergeGroup] if true, flatten all objects into the given container
130
130
  * @param {boolean} [options.setViewportBounds=true] if true, set the viewport bounds to the map size
131
131
  * @returns {boolean} true if the level was successfully loaded
@@ -4,7 +4,7 @@ import * as TMXUtils from "./TMXUtils.js";
4
4
  import Tile from "./TMXTile.js";
5
5
  import Renderable from "./../../renderable/renderable.js";
6
6
  import CanvasRenderer from "./../../video/canvas/canvas_renderer";
7
- import { world } from "./../../game.js";
7
+ import game from "./../../game.js";
8
8
 
9
9
  /**
10
10
  * Create required arrays for the given layer object
@@ -173,7 +173,7 @@ class TMXLayer extends Renderable {
173
173
 
174
174
  // check for the correct rendering method
175
175
  if (typeof (this.preRender) === "undefined") {
176
- this.preRender = world.preRender;
176
+ this.preRender = game.world.preRender;
177
177
  }
178
178
 
179
179
  // set a renderer
@@ -1,6 +1,6 @@
1
1
  import pool from "./../../system/pooling.js";
2
2
  import * as event from "./../../system/event.js";
3
- import { viewport } from "./../../game.js";
3
+ import game from "./../../game.js";
4
4
  import collision from "./../../physics/collision.js";
5
5
  import Body from "./../../physics/body.js";
6
6
  import TMXOrthogonalRenderer from "./renderer/TMXOrthogonalRenderer.js";
@@ -396,7 +396,7 @@ class TMXTileMap {
396
396
  */
397
397
  function _setBounds(width, height) {
398
398
  // adjust the viewport bounds if level is smaller
399
- viewport.setBounds(
399
+ game.viewport.setBounds(
400
400
  0, 0,
401
401
  Math.max(levelBounds.width, width),
402
402
  Math.max(levelBounds.height, height)
@@ -413,7 +413,7 @@ class TMXTileMap {
413
413
  if (setViewportBounds === true) {
414
414
  event.off(event.VIEWPORT_ONRESIZE, _setBounds);
415
415
  // force viewport bounds update
416
- _setBounds(viewport.width, viewport.height);
416
+ _setBounds(game.viewport.width, game.viewport.height);
417
417
  // Replace the resize handler
418
418
  event.on(event.VIEWPORT_ONRESIZE, _setBounds, this);
419
419
  }
@@ -1,10 +1,11 @@
1
1
  import * as fileUtil from "./../utils/file.js";
2
2
  import * as event from "./../system/event.js";
3
- import device from "./../system/device.js";
3
+ import { ua } from "./../system/platform.js";
4
4
  import * as audio from "./../audio/audio.js";
5
5
  import state from "./../state/state.js";
6
6
  import level from "./../level/level.js";
7
7
  import * as TMXUtils from "./../level/tiled/TMXUtils.js";
8
+ import { isDataUrl } from "./../utils/string.js";
8
9
 
9
10
 
10
11
  // contains all the images loaded
@@ -30,7 +31,7 @@ var timerId = 0;
30
31
  function checkLoadStatus(onload) {
31
32
  if (loadCount === resourceCount) {
32
33
  // wait 1/2s and execute callback (cheap workaround to ensure everything is loaded)
33
- if (onload || loader.onload) {
34
+ if (typeof onload === "function" || loader.onload) {
34
35
  // make sure we clear the timer
35
36
  clearTimeout(timerId);
36
37
  // trigger the onload callback
@@ -66,8 +67,12 @@ function checkLoadStatus(onload) {
66
67
  function preloadImage(img, onload, onerror) {
67
68
  // create new Image object and add to list
68
69
  imgList[img.name] = new Image();
69
- imgList[img.name].onload = onload;
70
- imgList[img.name].onerror = onerror;
70
+ if (typeof onload === "function") {
71
+ imgList[img.name].onload = onload;
72
+ }
73
+ if (typeof onerror === "function") {
74
+ imgList[img.name].onerror = onerror;
75
+ }
71
76
  if (typeof (loader.crossOrigin) === "string") {
72
77
  imgList[img.name].crossOrigin = loader.crossOrigin;
73
78
  }
@@ -83,17 +88,30 @@ function preloadImage(img, onload, onerror) {
83
88
  * @ignore
84
89
  */
85
90
  function preloadFontFace(data, onload, onerror) {
91
+
92
+ if (isDataUrl(data.src) === true) {
93
+ // make sure it in the `url(data:[<mediatype>][;base64],<data>)` format as expected by FontFace
94
+ if (!data.src.startsWith("url(")) {
95
+ data.src = "url(" + data.src + ")";
96
+ }
97
+ }
98
+
86
99
  var font = new FontFace(data.name, data.src);
100
+
87
101
  // loading promise
88
102
  font.load().then(() => {
89
103
  // apply the font after the font has finished downloading
90
104
  document.fonts.add(font);
91
105
  document.body.style.fontFamily = data.name;
92
- // onloaded callback
93
- onload();
106
+ if (typeof onload === "function") {
107
+ // onloaded callback
108
+ onload();
109
+ }
94
110
  }, function () {
95
- // rejected
96
- onerror(data.name);
111
+ if (typeof onerror === "function") {
112
+ // rejected
113
+ onerror(data.name);
114
+ }
97
115
  });
98
116
  };
99
117
 
@@ -119,7 +137,9 @@ function preloadTMX(tmxData, onload, onerror) {
119
137
  //if the data is in the tmxData object, don't get it via a XMLHTTPRequest
120
138
  if (tmxData.data) {
121
139
  addToTMXList(tmxData.data);
122
- onload();
140
+ if (typeof onload === "function") {
141
+ onload();
142
+ }
123
143
  return;
124
144
  }
125
145
 
@@ -153,7 +173,7 @@ function preloadTMX(tmxData, onload, onerror) {
153
173
  case "tmx":
154
174
  case "tsx":
155
175
  // ie9 does not fully implement the responseXML
156
- if (device.ua.match(/msie/i) || !xmlhttp.responseXML) {
176
+ if (ua.match(/msie/i) || !xmlhttp.responseXML) {
157
177
  if (globalThis.DOMParser) {
158
178
  // manually create the XML DOM
159
179
  result = (new DOMParser()).parseFromString(xmlhttp.responseText, "text/xml");
@@ -190,9 +210,11 @@ function preloadTMX(tmxData, onload, onerror) {
190
210
  addToTMXList(result);
191
211
 
192
212
  // fire the callback
193
- onload();
213
+ if (typeof onload === "function") {
214
+ onload();
215
+ }
194
216
  }
195
- else {
217
+ else if (typeof onerror === "function") {
196
218
  onerror(tmxData.name);
197
219
  }
198
220
  }
@@ -224,10 +246,12 @@ function preloadJSON(data, onload, onerror) {
224
246
  if ((xmlhttp.status === 200) || ((xmlhttp.status === 0) && xmlhttp.responseText)) {
225
247
  // get the Texture Packer Atlas content
226
248
  jsonList[data.name] = JSON.parse(xmlhttp.responseText);
227
- // fire the callback
228
- onload();
249
+ if (typeof onload === "function") {
250
+ // fire the callback
251
+ onload();
252
+ }
229
253
  }
230
- else {
254
+ else if (typeof onerror === "function") {
231
255
  onerror(data.name);
232
256
  }
233
257
  }
@@ -257,8 +281,11 @@ function preloadBinary(data, onload, onerror) {
257
281
  buffer[i] = String.fromCharCode(byteArray[i]);
258
282
  }
259
283
  binList[data.name] = buffer.join("");
260
- // callback
261
- onload();
284
+ if (typeof onload === "function") {
285
+ // callback
286
+ onload();
287
+ }
288
+
262
289
  }
263
290
  };
264
291
  httpReq.send();
@@ -278,15 +305,19 @@ function preloadJavascript(data, onload, onerror) {
278
305
  }
279
306
  script.defer = true;
280
307
 
281
- script.onload = () => {
282
- // callback
283
- onload();
284
- };
308
+ if (typeof onload === "function") {
309
+ script.onload = () => {
310
+ // callback
311
+ onload();
312
+ };
313
+ }
285
314
 
286
- script.onerror = () => {
287
- // callback
288
- onerror(data.name);
289
- };
315
+ if (typeof onerror === "function") {
316
+ script.onerror = () => {
317
+ // callback
318
+ onerror(data.name);
319
+ };
320
+ }
290
321
 
291
322
  document.getElementsByTagName("body")[0].appendChild(script);
292
323
  };
@@ -453,6 +484,8 @@ var loader = {
453
484
  * {name: "tileset-platformer", type: "image", src: "data/map/tileset.png"},
454
485
  * // PNG packed texture
455
486
  * {name: "texture", type:"image", src: "data/gfx/texture.png"}
487
+ * // PNG base64 encoded image
488
+ * {name: "texture", type:"image", src: "data:image/png;base64,iVBORw0KAAAQAAAAEACA..."}
456
489
  * // TSX file
457
490
  * {name: "meta_tiles", type: "tsx", src: "data/map/meta_tiles.tsx"},
458
491
  * // TMX level (XML & JSON)
@@ -463,6 +496,8 @@ var loader = {
463
496
  * // audio resources
464
497
  * {name: "bgmusic", type: "audio", src: "data/audio/"},
465
498
  * {name: "cling", type: "audio", src: "data/audio/"},
499
+ * // base64 encoded audio resources
500
+ * {name: "band", type: "audio", src: "data:audio/wav;base64,..."},
466
501
  * // binary file
467
502
  * {name: "ymTrack", type: "binary", src: "data/audio/main.ym"},
468
503
  * // JSON file (used for texturePacker)
@@ -509,13 +544,14 @@ var loader = {
509
544
  * @param {string} res.type "audio", binary", "image", "json", "tmx", "tsx"
510
545
  * @param {string} res.src path and/or file name of the resource (for audio assets only the path is required)
511
546
  * @param {boolean} [res.stream] Set to true to force HTML5 Audio, which allows not to wait for large file to be downloaded before playing.
512
- * @param {Function} onload function to be called when the resource is loaded
513
- * @param {Function} onerror function to be called in case of error
547
+ * @param {Function} [onload] function to be called when the resource is loaded
548
+ * @param {Function} [onerror] function to be called in case of error
514
549
  * @returns {number} the amount of corresponding resource to be preloaded
515
550
  * @example
516
551
  * // load an image asset
517
552
  * me.loader.load({name: "avatar", type:"image", src: "data/avatar.png"}, this.onload.bind(this), this.onerror.bind(this));
518
- *
553
+ * // load a base64 image asset
554
+ * me.loader.load({name: "avatar", type:"image", src: "data:image/png;base64,iVBORw0KAAAQAAAAEACA..."};
519
555
  * // start loading music
520
556
  * me.loader.load({
521
557
  * name : "bgmusic",
@@ -1,10 +1,11 @@
1
- import { world, viewport } from "./../game.js";
1
+ import game from "./../game.js";
2
2
  import { renderer } from "./../video/video.js";
3
3
  import * as event from "./../system/event.js";
4
- import {nextPowerOfTwo} from "./../math/math.js";
5
- import pool from "./../system/pooling.js";
4
+ import Sprite from "./../renderable/sprite.js";
6
5
  import Renderable from "./../renderable/renderable.js";
7
6
  import Stage from "./../state/stage.js";
7
+ import loader from "./loader.js";
8
+ import logo_url from "./melonjs_logo.png";
8
9
 
9
10
 
10
11
  // a basic progress bar object
@@ -40,7 +41,7 @@ class ProgressBar extends Renderable {
40
41
  * draw function
41
42
  * @ignore
42
43
  */
43
- draw (renderer) {
44
+ draw(renderer, viewport) {
44
45
  // draw the progress bar
45
46
  renderer.setColor("black");
46
47
  renderer.fillRect(this.pos.x, viewport.centerY, renderer.getWidth(), this.barHeight / 2);
@@ -61,71 +62,6 @@ class ProgressBar extends Renderable {
61
62
 
62
63
  };
63
64
 
64
- // the melonJS Logo
65
- class IconLogo extends Renderable {
66
- /**
67
- * @ignore
68
- */
69
- constructor(x, y) {
70
- super(x, y, 100, 85);
71
-
72
- this.iconTexture = pool.pull("CanvasTexture",
73
- renderer.WebGLVersion > 1 ? this.width : nextPowerOfTwo(this.width),
74
- renderer.WebGLVersion > 1 ? this.height : nextPowerOfTwo(this.height),
75
- { offscreenCanvas: true }
76
- );
77
-
78
- var context = this.iconTexture.context;
79
-
80
- context.beginPath();
81
- context.moveTo(0.7, 48.9);
82
- context.bezierCurveTo(10.8, 68.9, 38.4, 75.8, 62.2, 64.5);
83
- context.bezierCurveTo(86.1, 53.1, 97.2, 27.7, 87.0, 7.7);
84
- context.lineTo(87.0, 7.7);
85
- context.bezierCurveTo(89.9, 15.4, 73.9, 30.2, 50.5, 41.4);
86
- context.bezierCurveTo(27.1, 52.5, 5.2, 55.8, 0.7, 48.9);
87
- context.lineTo(0.7, 48.9);
88
- context.closePath();
89
- context.fillStyle = "rgb(255, 255, 255)";
90
- context.fill();
91
-
92
- context.beginPath();
93
- context.moveTo(84.0, 7.0);
94
- context.bezierCurveTo(87.6, 14.7, 72.5, 30.2, 50.2, 41.6);
95
- context.bezierCurveTo(27.9, 53.0, 6.9, 55.9, 3.2, 48.2);
96
- context.bezierCurveTo(-0.5, 40.4, 14.6, 24.9, 36.9, 13.5);
97
- context.bezierCurveTo(59.2, 2.2, 80.3, -0.8, 84.0, 7.0);
98
- context.lineTo(84.0, 7.0);
99
- context.closePath();
100
- context.lineWidth = 5.3;
101
- context.strokeStyle = "rgb(255, 255, 255)";
102
- context.lineJoin = "miter";
103
- context.miterLimit = 4.0;
104
- context.stroke();
105
-
106
- this.anchorPoint.set(0.5, 0.5);
107
- }
108
-
109
- /**
110
- * @ignore
111
- */
112
- draw(renderer) {
113
- renderer.drawImage(this.iconTexture.canvas, renderer.getWidth() / 2, this.pos.y);
114
- }
115
-
116
- /**
117
- * Destroy function
118
- * @ignore
119
- */
120
- destroy() {
121
- // call the parent destroy method
122
- super.destroy(arguments);
123
- pool.push(this.iconTexture);
124
- this.iconTexture = undefined;
125
- }
126
- };
127
-
128
-
129
65
  /**
130
66
  * a default loading screen
131
67
  * @ignore
@@ -139,60 +75,37 @@ class DefaultLoadingScreen extends Stage {
139
75
  var barHeight = 8;
140
76
 
141
77
  // set a background color
142
- world.backgroundColor.parseCSS("#202020");
78
+ game.world.backgroundColor.parseCSS("#202020");
143
79
 
144
80
  // progress bar
145
- world.addChild(new ProgressBar(
81
+ game.world.addChild(new ProgressBar(
146
82
  0,
147
83
  renderer.getHeight() / 2,
148
84
  renderer.getWidth(),
149
85
  barHeight
150
86
  ), 1);
151
87
 
152
- // melonJS logo
153
- world.addChild(new IconLogo(
154
- renderer.getWidth() / 2,
155
- (renderer.getHeight() / 2) - (barHeight * 2) - 35
156
-
157
- ), 2);
158
-
159
- var logo1 = pool.pull("Text",
160
- renderer.getWidth() / 2,
161
- (renderer.getHeight() / 2) + 16, {
162
- font: "century gothic",
163
- size: 32,
164
- fillStyle: "white",
165
- textAlign: "left",
166
- textBaseline : "top",
167
- text: "melon",
168
- offScreenCanvas: renderer.WebGLVersion >= 1
169
- }
170
- );
171
- logo1.anchorPoint.set(0, 0);
172
-
173
- var logo2 = pool.pull("Text",
174
- renderer.getWidth() / 2,
175
- (renderer.getHeight() / 2) + 16, {
176
- font: "century gothic",
177
- size: 32,
178
- fillStyle: "#55aa00",
179
- textAlign: "left",
180
- textBaseline : "top",
181
- bold: true,
182
- text: "JS",
183
- offScreenCanvas: renderer.WebGLVersion >= 1
184
- }
185
- );
186
- logo2.anchorPoint.set(0, 0);
187
-
188
- // adjust position of both text
189
- var text_width = logo1.getBounds().width + logo2.getBounds().width;
190
- logo1.pos.x = renderer.getWidth() / 2 - text_width / 2;
191
- logo2.pos.x = logo1.pos.x + logo1.getBounds().width;
192
-
193
- // melonJS text
194
- world.addChild(logo1, 2);
195
- world.addChild(logo2, 2);
88
+ // load the melonJS logo
89
+ loader.load({name: "melonjs_logo", type: "image", src: logo_url}, () => {
90
+ // melonJS logo
91
+ game.world.addChild(new Sprite(
92
+ renderer.getWidth() / 2,
93
+ renderer.getHeight() / 2, {
94
+ image : "melonjs_logo",
95
+ framewidth : 256,
96
+ frameheight : 256
97
+ }), 2
98
+ );
99
+ });
100
+ }
101
+
102
+ /**
103
+ * Called by engine before deleting the object
104
+ * @ignore
105
+ */
106
+ onDestroyEvent() {
107
+ // cancel the callback
108
+ loader.unload({name: "melonjs_logo", type:"image"});
196
109
  }
197
110
  };
198
111
 
Binary file