melonjs 12.0.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.
- package/LICENSE.md +1 -1
- package/README.md +4 -6
- package/dist/melonjs.js +22325 -22327
- package/dist/melonjs.min.js +5 -6
- package/dist/melonjs.module.d.ts +184 -171
- package/dist/melonjs.module.js +20780 -20771
- package/package.json +12 -13
- package/src/application/application.js +231 -0
- package/src/audio/audio.js +8 -2
- package/src/camera/camera2d.js +6 -6
- package/src/game.js +9 -232
- package/src/index.js +3 -3
- package/src/input/keyboard.js +2 -2
- package/src/input/pointer.js +4 -5
- package/src/input/pointerevent.js +8 -8
- package/src/lang/deprecated.js +0 -29
- package/src/level/level.js +2 -2
- package/src/level/tiled/TMXLayer.js +2 -2
- package/src/level/tiled/TMXTileMap.js +3 -3
- package/src/loader/loader.js +64 -28
- package/src/loader/loadingscreen.js +27 -28
- package/src/physics/body.js +27 -51
- package/src/physics/detector.js +3 -3
- package/src/physics/quadtree.js +58 -29
- package/src/physics/world.js +32 -3
- package/src/renderable/container.js +2 -2
- package/src/renderable/imagelayer.js +8 -8
- package/src/renderable/trigger.js +4 -4
- package/src/state/stage.js +1 -1
- package/src/state/state.js +50 -3
- package/src/system/device.js +814 -981
- package/src/system/event.js +2 -1
- package/src/system/platform.js +32 -0
- package/src/system/save.js +23 -14
- package/src/system/timer.js +12 -35
- package/src/text/text.js +9 -12
- package/src/tweens/tween.js +6 -6
- package/src/utils/string.js +13 -0
- package/src/video/canvas/canvas_renderer.js +3 -2
- package/src/video/renderer.js +2 -2
- package/src/video/texture/canvas_texture.js +36 -2
- package/src/video/video.js +15 -9
- package/src/video/webgl/glshader.js +1 -1
- package/src/video/webgl/webgl_renderer.js +1 -1
package/src/system/event.js
CHANGED
|
@@ -399,7 +399,8 @@ export const CANVAS_ONRESIZE = "canvas.onresize";
|
|
|
399
399
|
* Event for when the viewport is resized <br>
|
|
400
400
|
* (this usually follows a WINDOW_ONRESIZE event, when using the `flex` scaling mode is used and after the viewport was updated).<br>
|
|
401
401
|
* Data passed : {number} viewport width <br>
|
|
402
|
-
* Data passed : {number} viewport height
|
|
402
|
+
* Data passed : {number} viewport height <br>
|
|
403
|
+
* Data passed : {Camera2d} a reference to the camera viewport being resized
|
|
403
404
|
* @public
|
|
404
405
|
* @constant
|
|
405
406
|
* @type {string}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The device platform type
|
|
3
|
+
* @namespace platform
|
|
4
|
+
* @memberof device
|
|
5
|
+
* @property {string} ua the user agent string for the current device
|
|
6
|
+
* @property {boolean} iOS `true` if the device is an iOS platform
|
|
7
|
+
* @property {boolean} android `true` if the device is an Android platform
|
|
8
|
+
* @property {boolean} android2 `true` if the device is an Android 2.x platform
|
|
9
|
+
* @property {boolean} linux `true` if the device is a Linux platform
|
|
10
|
+
* @property {boolean} chromeOS `true` if the device is running on ChromeOS.
|
|
11
|
+
* @property {boolean} wp `true` if the device is a Windows Phone platform
|
|
12
|
+
* @property {boolean} BlackBerry`true` if the device is a BlackBerry platform
|
|
13
|
+
* @property {boolean} Kindle`true` if the device is a Kindle platform
|
|
14
|
+
* @property {boolean} ejecta `true` if running under Ejecta
|
|
15
|
+
* @property {boolean} isWeixin `true` if running under Wechat
|
|
16
|
+
* @property {boolean} nodeJS `true` if running under node.js
|
|
17
|
+
* @property {boolean} isMobile `true` if a mobile device
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
export const ua = typeof globalThis.navigator !== "undefined" ? globalThis.navigator.userAgent : "";
|
|
21
|
+
export const iOS = /iPhone|iPad|iPod/i.test(ua);
|
|
22
|
+
export const android = /Android/i.test(ua);
|
|
23
|
+
export const android2 = /Android 2/i.test(ua);
|
|
24
|
+
export const linux = /Linux/i.test(ua);
|
|
25
|
+
export const chromeOS = /CrOS/.test(ua);
|
|
26
|
+
export const wp = /Windows Phone/i.test(ua);
|
|
27
|
+
export const BlackBerry = /BlackBerry/i.test(ua);
|
|
28
|
+
export const Kindle = /Kindle|Silk.*Mobile Safari/i.test(ua);
|
|
29
|
+
export const ejecta = (typeof globalThis.ejecta !== "undefined");
|
|
30
|
+
export const isWeixin = /MicroMessenger/i.test(ua);
|
|
31
|
+
export const nodeJS = (typeof globalThis.process !== "undefined") && (typeof globalThis.process.release !== "undefined") && (globalThis.process.release.name === "node");
|
|
32
|
+
export const isMobile = /Mobi/i.test(ua) || iOS || android || wp || BlackBerry || Kindle || false;
|
package/src/system/save.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import device from "./device.js";
|
|
2
1
|
import * as event from "./event.js";
|
|
3
2
|
|
|
4
3
|
/**
|
|
@@ -32,22 +31,32 @@ import * as event from "./event.js";
|
|
|
32
31
|
* @namespace save
|
|
33
32
|
*/
|
|
34
33
|
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
// Variable to hold the object data
|
|
35
|
+
var data = {};
|
|
37
36
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
37
|
+
let hasLocalStorage = false;
|
|
38
|
+
|
|
39
|
+
try {
|
|
40
|
+
// true if localStorage is supported
|
|
41
|
+
hasLocalStorage = typeof globalThis !== "undefined" && typeof globalThis.localStorage !== "undefined";
|
|
42
|
+
} catch (e) {
|
|
43
|
+
// the above generates an exception when cookies are blocked
|
|
44
|
+
hasLocalStorage = false;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* a function to check if the given key is a reserved word
|
|
49
|
+
* @ignore
|
|
50
|
+
*/
|
|
51
|
+
function isReserved(key) {
|
|
52
|
+
return (key === "add" || key === "remove");
|
|
53
|
+
}
|
|
45
54
|
|
|
46
55
|
|
|
47
56
|
// Initialize me.save on Boot event
|
|
48
57
|
event.on(event.BOOT, () => {
|
|
49
58
|
// Load previous data if local Storage is supported
|
|
50
|
-
if (
|
|
59
|
+
if (hasLocalStorage === true) {
|
|
51
60
|
var me_save_content = globalThis.localStorage.getItem("me.save");
|
|
52
61
|
|
|
53
62
|
if (typeof me_save_content === "string" && me_save_content.length > 0) {
|
|
@@ -95,7 +104,7 @@ var save = {
|
|
|
95
104
|
*/
|
|
96
105
|
set (value) {
|
|
97
106
|
data[prop] = value;
|
|
98
|
-
if (
|
|
107
|
+
if (hasLocalStorage === true) {
|
|
99
108
|
globalThis.localStorage.setItem("me.save." + prop, JSON.stringify(value));
|
|
100
109
|
}
|
|
101
110
|
}
|
|
@@ -109,7 +118,7 @@ var save = {
|
|
|
109
118
|
});
|
|
110
119
|
|
|
111
120
|
// Save keys
|
|
112
|
-
if (
|
|
121
|
+
if (hasLocalStorage === true) {
|
|
113
122
|
globalThis.localStorage.setItem("me.save", JSON.stringify(Object.keys(data)));
|
|
114
123
|
}
|
|
115
124
|
},
|
|
@@ -127,7 +136,7 @@ var save = {
|
|
|
127
136
|
if (!isReserved(key)) {
|
|
128
137
|
if (typeof data[key] !== "undefined") {
|
|
129
138
|
delete data[key];
|
|
130
|
-
if (
|
|
139
|
+
if (hasLocalStorage === true) {
|
|
131
140
|
globalThis.localStorage.removeItem("me.save." + key);
|
|
132
141
|
globalThis.localStorage.setItem("me.save", JSON.stringify(Object.keys(data)));
|
|
133
142
|
}
|
package/src/system/timer.js
CHANGED
|
@@ -6,53 +6,46 @@ import { clamp } from "./../math/math.js";
|
|
|
6
6
|
/**
|
|
7
7
|
* @classdesc
|
|
8
8
|
* a Timer class to manage timing related function (FPS, Game Tick, Time...)
|
|
9
|
-
|
|
9
|
+
* @see {@link timer} the default global timer instance
|
|
10
10
|
*/
|
|
11
11
|
class Timer {
|
|
12
12
|
|
|
13
13
|
constructor() {
|
|
14
14
|
/**
|
|
15
|
-
* Last game tick value
|
|
16
|
-
* Use this value to scale velocities during frame drops due to slow
|
|
17
|
-
*
|
|
18
|
-
* This feature is disabled by default. Enable me.timer.interpolation to
|
|
19
|
-
* use it.
|
|
15
|
+
* Last game tick value. <br>
|
|
16
|
+
* Use this value to scale velocities during frame drops due to slow hardware or when setting an FPS limit.
|
|
17
|
+
* This feature is disabled by default (Enable interpolation to use it).
|
|
20
18
|
* @public
|
|
21
|
-
* @see
|
|
19
|
+
* @see interpolation
|
|
20
|
+
* @See maxfps
|
|
22
21
|
* @type {number}
|
|
23
22
|
* @name tick
|
|
24
|
-
* @memberof timer
|
|
25
23
|
*/
|
|
26
24
|
this.tick = 1.0;
|
|
27
25
|
|
|
28
26
|
/**
|
|
29
|
-
* Last measured fps rate.<br
|
|
30
|
-
* This feature is disabled by default, unless the debugPanel is enabled/visible
|
|
27
|
+
* Last measured fps rate.<br>
|
|
28
|
+
* This feature is disabled by default, unless the debugPanel is enabled/visible.
|
|
31
29
|
* @public
|
|
32
30
|
* @type {number}
|
|
33
31
|
* @name fps
|
|
34
|
-
* @memberof timer
|
|
35
32
|
*/
|
|
36
33
|
this.fps = 0;
|
|
37
34
|
|
|
38
35
|
/**
|
|
39
36
|
* Set the maximum target display frame per second
|
|
40
37
|
* @public
|
|
41
|
-
* @see
|
|
38
|
+
* @see tick
|
|
42
39
|
* @type {number}
|
|
43
|
-
* @name maxfps
|
|
44
40
|
* @default 60
|
|
45
|
-
* @memberof timer
|
|
46
41
|
*/
|
|
47
42
|
this.maxfps = 60;
|
|
48
43
|
|
|
49
44
|
/**
|
|
50
45
|
* Enable/disable frame interpolation
|
|
51
|
-
* @see
|
|
46
|
+
* @see tick
|
|
52
47
|
* @type {boolean}
|
|
53
48
|
* @default false
|
|
54
|
-
* @name interpolation
|
|
55
|
-
* @memberof timer
|
|
56
49
|
*/
|
|
57
50
|
this.interpolation = false;
|
|
58
51
|
|
|
@@ -96,8 +89,6 @@ class Timer {
|
|
|
96
89
|
|
|
97
90
|
/**
|
|
98
91
|
* reset time (e.g. usefull in case of pause)
|
|
99
|
-
* @name reset
|
|
100
|
-
* @memberof timer
|
|
101
92
|
* @ignore
|
|
102
93
|
*/
|
|
103
94
|
reset() {
|
|
@@ -114,8 +105,6 @@ class Timer {
|
|
|
114
105
|
|
|
115
106
|
/**
|
|
116
107
|
* Calls a function once after a specified delay. See me.timer.setInterval to repeativly call a function.
|
|
117
|
-
* @name setTimeout
|
|
118
|
-
* @memberof timer
|
|
119
108
|
* @param {Function} fn the function you want to execute after delay milliseconds.
|
|
120
109
|
* @param {number} delay the number of milliseconds (thousandths of a second) that the function call should be delayed by.
|
|
121
110
|
* @param {boolean} [pauseable=true] respects the pause state of the engine.
|
|
@@ -142,8 +131,6 @@ class Timer {
|
|
|
142
131
|
|
|
143
132
|
/**
|
|
144
133
|
* Calls a function continously at the specified interval. See setTimeout to call function a single time.
|
|
145
|
-
* @name setInterval
|
|
146
|
-
* @memberof timer
|
|
147
134
|
* @param {Function} fn the function to execute
|
|
148
135
|
* @param {number} delay the number of milliseconds (thousandths of a second) on how often to execute the function
|
|
149
136
|
* @param {boolean} [pauseable=true] respects the pause state of the engine.
|
|
@@ -170,8 +157,6 @@ class Timer {
|
|
|
170
157
|
|
|
171
158
|
/**
|
|
172
159
|
* Clears the delay set by me.timer.setTimeout().
|
|
173
|
-
* @name clearTimeout
|
|
174
|
-
* @memberof timer
|
|
175
160
|
* @param {number} timeoutID ID of the timeout to be cleared
|
|
176
161
|
*/
|
|
177
162
|
clearTimeout(timeoutID) {
|
|
@@ -180,8 +165,6 @@ class Timer {
|
|
|
180
165
|
|
|
181
166
|
/**
|
|
182
167
|
* Clears the Interval set by me.timer.setInterval().
|
|
183
|
-
* @name clearInterval
|
|
184
|
-
* @memberof timer
|
|
185
168
|
* @param {number} intervalID ID of the interval to be cleared
|
|
186
169
|
*/
|
|
187
170
|
clearInterval(intervalID) {
|
|
@@ -191,8 +174,6 @@ class Timer {
|
|
|
191
174
|
/**
|
|
192
175
|
* Return the current timestamp in milliseconds <br>
|
|
193
176
|
* since the game has started or since linux epoch (based on browser support for High Resolution Timer)
|
|
194
|
-
* @name getTime
|
|
195
|
-
* @memberof timer
|
|
196
177
|
* @returns {number}
|
|
197
178
|
*/
|
|
198
179
|
getTime() {
|
|
@@ -201,8 +182,6 @@ class Timer {
|
|
|
201
182
|
|
|
202
183
|
/**
|
|
203
184
|
* Return elapsed time in milliseconds since the last update
|
|
204
|
-
* @name getDelta
|
|
205
|
-
* @memberof timer
|
|
206
185
|
* @returns {number}
|
|
207
186
|
*/
|
|
208
187
|
getDelta() {
|
|
@@ -211,9 +190,7 @@ class Timer {
|
|
|
211
190
|
|
|
212
191
|
/**
|
|
213
192
|
* compute the actual frame time and fps rate
|
|
214
|
-
* @name computeFPS
|
|
215
193
|
* @ignore
|
|
216
|
-
* @memberof timer
|
|
217
194
|
*/
|
|
218
195
|
countFPS() {
|
|
219
196
|
this.framecount++;
|
|
@@ -281,6 +258,8 @@ class Timer {
|
|
|
281
258
|
}
|
|
282
259
|
};
|
|
283
260
|
|
|
261
|
+
const timer = new Timer();
|
|
262
|
+
|
|
284
263
|
/**
|
|
285
264
|
* the default global Timer instance
|
|
286
265
|
* @namespace timer
|
|
@@ -295,6 +274,4 @@ class Timer {
|
|
|
295
274
|
* // set a timer to call "myFunction" every 1000ms (respecting the pause state) and passing param1 and param2
|
|
296
275
|
* timer.setInterval(myFunction, 1000, true, param1, param2);
|
|
297
276
|
*/
|
|
298
|
-
const timer = new Timer();
|
|
299
|
-
|
|
300
277
|
export default timer;
|
package/src/text/text.js
CHANGED
|
@@ -204,18 +204,6 @@ class Text extends Renderable {
|
|
|
204
204
|
this.setText(settings.text);
|
|
205
205
|
}
|
|
206
206
|
|
|
207
|
-
/** @ignore */
|
|
208
|
-
onDeactivateEvent() {
|
|
209
|
-
// free the canvas and potential corresponding texture when deactivated
|
|
210
|
-
if (this.offScreenCanvas === true) {
|
|
211
|
-
globalRenderer.currentCompositor.deleteTexture2D(globalRenderer.currentCompositor.getTexture2D(this.glTextureUnit));
|
|
212
|
-
globalRenderer.cache.delete(this.canvasTexture.canvas);
|
|
213
|
-
pool.push(this.canvasTexture);
|
|
214
|
-
this.canvasTexture = undefined;
|
|
215
|
-
this.glTextureUnit = undefined;
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
|
|
219
207
|
/**
|
|
220
208
|
* make the font bold
|
|
221
209
|
* @returns {Text} this object for chaining
|
|
@@ -436,6 +424,15 @@ class Text extends Renderable {
|
|
|
436
424
|
* @ignore
|
|
437
425
|
*/
|
|
438
426
|
destroy() {
|
|
427
|
+
if (this.offScreenCanvas === true) {
|
|
428
|
+
if (globalRenderer instanceof WebGLRenderer) {
|
|
429
|
+
globalRenderer.currentCompositor.deleteTexture2D(globalRenderer.currentCompositor.getTexture2D(this.glTextureUnit));
|
|
430
|
+
this.glTextureUnit = undefined;
|
|
431
|
+
}
|
|
432
|
+
globalRenderer.cache.delete(this.canvasTexture.canvas);
|
|
433
|
+
pool.push(this.canvasTexture);
|
|
434
|
+
this.canvasTexture = undefined;
|
|
435
|
+
}
|
|
439
436
|
pool.push(this.fillStyle);
|
|
440
437
|
pool.push(this.strokeStyle);
|
|
441
438
|
this.fillStyle = this.strokeStyle = undefined;
|
package/src/tweens/tween.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import timer from "./../system/timer.js";
|
|
2
2
|
import * as event from "./../system/event.js";
|
|
3
|
-
import
|
|
3
|
+
import game from "./../game.js";
|
|
4
4
|
import { Easing } from "./easing.js";
|
|
5
5
|
import { Interpolation } from "./interpolation.js";
|
|
6
6
|
|
|
@@ -72,7 +72,7 @@ class Tween {
|
|
|
72
72
|
this._onUpdateCallback = null;
|
|
73
73
|
this._onCompleteCallback = null;
|
|
74
74
|
// tweens are synchronized with the game update loop
|
|
75
|
-
this._tweenTimeTracker = lastUpdate;
|
|
75
|
+
this._tweenTimeTracker = game.lastUpdate;
|
|
76
76
|
|
|
77
77
|
// reset flags to default value
|
|
78
78
|
this.isPersistent = false;
|
|
@@ -170,7 +170,7 @@ class Tween {
|
|
|
170
170
|
this._onStartCallbackFired = false;
|
|
171
171
|
|
|
172
172
|
// add the tween to the object pool on start
|
|
173
|
-
world.addChild(this);
|
|
173
|
+
game.world.addChild(this);
|
|
174
174
|
|
|
175
175
|
this._startTime = time + this._delayTime;
|
|
176
176
|
|
|
@@ -212,7 +212,7 @@ class Tween {
|
|
|
212
212
|
*/
|
|
213
213
|
stop() {
|
|
214
214
|
// remove the tween from the world container
|
|
215
|
-
world.removeChildNow(this);
|
|
215
|
+
game.world.removeChildNow(this);
|
|
216
216
|
return this;
|
|
217
217
|
}
|
|
218
218
|
|
|
@@ -349,7 +349,7 @@ class Tween {
|
|
|
349
349
|
|
|
350
350
|
// the original Tween implementation expect
|
|
351
351
|
// a timestamp and not a time delta
|
|
352
|
-
this._tweenTimeTracker = (lastUpdate > this._tweenTimeTracker) ? lastUpdate : this._tweenTimeTracker + dt;
|
|
352
|
+
this._tweenTimeTracker = (game.lastUpdate > this._tweenTimeTracker) ? game.lastUpdate : this._tweenTimeTracker + dt;
|
|
353
353
|
var time = this._tweenTimeTracker;
|
|
354
354
|
|
|
355
355
|
var property;
|
|
@@ -442,7 +442,7 @@ class Tween {
|
|
|
442
442
|
|
|
443
443
|
} else {
|
|
444
444
|
// remove the tween from the world container
|
|
445
|
-
world.removeChildNow(this);
|
|
445
|
+
game.world.removeChildNow(this);
|
|
446
446
|
|
|
447
447
|
if ( this._onCompleteCallback !== null ) {
|
|
448
448
|
|
package/src/utils/string.js
CHANGED
|
@@ -58,3 +58,16 @@ export function toHex(str) {
|
|
|
58
58
|
}
|
|
59
59
|
return res;
|
|
60
60
|
};
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* returns true if the given string is a data url in the `data:[<mediatype>][;base64],<data>` format.
|
|
64
|
+
* (this will not test the validity of the Data or Base64 encoding)
|
|
65
|
+
* @public
|
|
66
|
+
* @memberof utils.string
|
|
67
|
+
* @name isDataUrl
|
|
68
|
+
* @param {string} str the string (url) to be tested
|
|
69
|
+
* @returns {boolean} true if the string is a data url
|
|
70
|
+
*/
|
|
71
|
+
export function isDataUrl(str) {
|
|
72
|
+
return /^data:(.+);base64,(.+)$/.test(str);
|
|
73
|
+
};
|
|
@@ -743,11 +743,11 @@ class CanvasRenderer extends Renderer {
|
|
|
743
743
|
}
|
|
744
744
|
|
|
745
745
|
// https://github.com/melonjs/melonJS/issues/648
|
|
746
|
-
|
|
746
|
+
if (mask instanceof RoundRect) {
|
|
747
747
|
context.roundRect(mask.top, mask.left, mask.width, mask.height, mask.radius);
|
|
748
748
|
} else if (mask instanceof Rect || mask instanceof Bounds) {
|
|
749
749
|
context.rect(mask.top, mask.left, mask.width, mask.height);
|
|
750
|
-
}
|
|
750
|
+
} else if (mask instanceof Ellipse) {
|
|
751
751
|
const _x = mask.pos.x, _y = mask.pos.y,
|
|
752
752
|
hw = mask.radiusV.x,
|
|
753
753
|
hh = mask.radiusV.y,
|
|
@@ -769,6 +769,7 @@ class CanvasRenderer extends Renderer {
|
|
|
769
769
|
context.bezierCurveTo(xmin, by, lx, ymax, lx, _y);
|
|
770
770
|
context.bezierCurveTo(lx, ymin, xmin, ty, _x, ty);
|
|
771
771
|
} else {
|
|
772
|
+
// polygon
|
|
772
773
|
const _x = mask.pos.x, _y = mask.pos.y;
|
|
773
774
|
var point;
|
|
774
775
|
|
package/src/video/renderer.js
CHANGED
|
@@ -2,7 +2,7 @@ import Color from "./../math/color.js";
|
|
|
2
2
|
import Matrix3d from "./../math/matrix3.js";
|
|
3
3
|
import { createCanvas, renderer } from "./video.js";
|
|
4
4
|
import * as event from "./../system/event.js";
|
|
5
|
-
import device from "./../system/device.js";
|
|
5
|
+
import * as device from "./../system/device.js";
|
|
6
6
|
import { setPrefixed } from "./../utils/agent.js";
|
|
7
7
|
import Rect from "./../geometries/rectangle.js";
|
|
8
8
|
import RoundRect from "./../geometries/roundrect.js";
|
|
@@ -22,7 +22,7 @@ class Renderer {
|
|
|
22
22
|
* @param {number} options.width The width of the canvas without scaling
|
|
23
23
|
* @param {number} options.height The height of the canvas without scaling
|
|
24
24
|
* @param {HTMLCanvasElement} [options.canvas] The html canvas to draw to on screen
|
|
25
|
-
* @param {boolean} [options.doubleBuffering=false] Whether to enable double buffering
|
|
25
|
+
* @param {boolean} [options.doubleBuffering=false] Whether to enable double buffering (not applicable when using the WebGL Renderer)
|
|
26
26
|
* @param {boolean} [options.antiAlias=false] Whether to enable anti-aliasing, use false (default) for a pixelated effect.
|
|
27
27
|
* @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.
|
|
28
28
|
* @param {boolean} [options.transparent=false] Whether to enable transparency on the canvas (performance hit when enabled)
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { createCanvas } from "./../video.js";
|
|
2
|
+
import { setPrefixed } from "./../../utils/agent.js";
|
|
2
3
|
|
|
3
|
-
// default
|
|
4
|
+
// default canvas settings
|
|
4
5
|
var defaultAttributes = {
|
|
5
6
|
offscreenCanvas : false,
|
|
6
|
-
willReadFrequently : false
|
|
7
|
+
willReadFrequently : false,
|
|
8
|
+
antiAlias : false
|
|
7
9
|
};
|
|
8
10
|
|
|
9
11
|
/**
|
|
@@ -16,6 +18,7 @@ class CanvasTexture {
|
|
|
16
18
|
* @param {object} attributes The attributes to create both the canvas and 2d context
|
|
17
19
|
* @param {boolean} [attributes.offscreenCanvas=false] will create an offscreenCanvas if true instead of a standard canvas
|
|
18
20
|
* @param {boolean} [attributes.willReadFrequently=false] Indicates whether or not a lot of read-back operations are planned
|
|
21
|
+
* @param {boolean} [attributes.antiAlias=false] Whether to enable anti-aliasing, use false (default) for a pixelated effect.
|
|
19
22
|
*/
|
|
20
23
|
constructor(width, height, attributes = defaultAttributes) {
|
|
21
24
|
|
|
@@ -33,6 +36,9 @@ class CanvasTexture {
|
|
|
33
36
|
* @type {CanvasRenderingContext2D}
|
|
34
37
|
*/
|
|
35
38
|
this.context = this.canvas.getContext("2d", { willReadFrequently: attributes.willReadFrequently });
|
|
39
|
+
|
|
40
|
+
// enable or disable antiAlias if specified
|
|
41
|
+
this.setAntiAlias(attributes.antiAlias);
|
|
36
42
|
}
|
|
37
43
|
|
|
38
44
|
/**
|
|
@@ -51,6 +57,34 @@ class CanvasTexture {
|
|
|
51
57
|
this.context.clearRect(0, 0, this.canvas.width, this.canvas.height);
|
|
52
58
|
}
|
|
53
59
|
|
|
60
|
+
/**
|
|
61
|
+
* enable/disable image smoothing (scaling interpolation)
|
|
62
|
+
* @param {boolean} [enable=false]
|
|
63
|
+
*/
|
|
64
|
+
setAntiAlias(enable = false) {
|
|
65
|
+
var canvas = this.canvas;
|
|
66
|
+
|
|
67
|
+
// enable/disable antialias on the given Context2d object
|
|
68
|
+
setPrefixed("imageSmoothingEnabled", enable, this.context);
|
|
69
|
+
|
|
70
|
+
// set antialias CSS property on the main canvas
|
|
71
|
+
if (typeof canvas.style !== "undefined") {
|
|
72
|
+
if (enable !== true) {
|
|
73
|
+
// https://developer.mozilla.org/en-US/docs/Web/CSS/image-rendering
|
|
74
|
+
canvas.style["image-rendering"] = "optimizeSpeed"; // legal fallback
|
|
75
|
+
canvas.style["image-rendering"] = "-moz-crisp-edges"; // Firefox
|
|
76
|
+
canvas.style["image-rendering"] = "-o-crisp-edges"; // Opera
|
|
77
|
+
canvas.style["image-rendering"] = "-webkit-optimize-contrast"; // Safari
|
|
78
|
+
canvas.style["image-rendering"] = "optimize-contrast"; // CSS 3
|
|
79
|
+
canvas.style["image-rendering"] = "crisp-edges"; // CSS 4
|
|
80
|
+
canvas.style["image-rendering"] = "pixelated"; // CSS 4
|
|
81
|
+
canvas.style.msInterpolationMode = "nearest-neighbor"; // IE8+
|
|
82
|
+
} else {
|
|
83
|
+
canvas.style["image-rendering"] = "auto";
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
54
88
|
/**
|
|
55
89
|
* Resizes the canvas texture to the given width and height.
|
|
56
90
|
* @param {number} width the desired width
|
package/src/video/video.js
CHANGED
|
@@ -3,8 +3,8 @@ import WebGLRenderer from "./webgl/webgl_renderer.js";
|
|
|
3
3
|
import CanvasRenderer from "./canvas/canvas_renderer.js";
|
|
4
4
|
import utils from "./../utils/utils.js";
|
|
5
5
|
import * as event from "./../system/event.js";
|
|
6
|
-
import
|
|
7
|
-
import device from "./../system/device.js";
|
|
6
|
+
import game from "./../game.js";
|
|
7
|
+
import * as device from "./../system/device.js";
|
|
8
8
|
import { initialized, version } from "./../index.js";
|
|
9
9
|
|
|
10
10
|
/**
|
|
@@ -302,7 +302,7 @@ export function init(width, height, options) {
|
|
|
302
302
|
false
|
|
303
303
|
);
|
|
304
304
|
|
|
305
|
-
if (device.
|
|
305
|
+
if (device.screenOrientation === true) {
|
|
306
306
|
globalThis.screen.orientation.onchange = function (e) {
|
|
307
307
|
event.emit(event.WINDOW_ONORIENTATION_CHANGE, e);
|
|
308
308
|
};
|
|
@@ -339,6 +339,12 @@ export function init(width, height, options) {
|
|
|
339
339
|
parent = device.getElement(typeof settings.parent !== "undefined" ? settings.parent : document.body);
|
|
340
340
|
parent.appendChild(renderer.getScreenCanvas());
|
|
341
341
|
|
|
342
|
+
// Mobile browser hacks
|
|
343
|
+
if (device.platform.isMobile) {
|
|
344
|
+
// Prevent the webview from moving on a swipe
|
|
345
|
+
device.enableSwipe(false);
|
|
346
|
+
}
|
|
347
|
+
|
|
342
348
|
// trigger an initial resize();
|
|
343
349
|
onresize();
|
|
344
350
|
|
|
@@ -362,7 +368,7 @@ export function init(width, height, options) {
|
|
|
362
368
|
renderType + " renderer" + gpu_renderer + " | " +
|
|
363
369
|
audioType + " | " +
|
|
364
370
|
"pixel ratio " + device.devicePixelRatio + " | " +
|
|
365
|
-
(device.nodeJS ? "node.js" : device.isMobile ? "mobile" : "desktop") + " | " +
|
|
371
|
+
(device.platform.nodeJS ? "node.js" : device.platform.isMobile ? "mobile" : "desktop") + " | " +
|
|
366
372
|
device.getScreenOrientation() + " | " +
|
|
367
373
|
device.language
|
|
368
374
|
);
|
|
@@ -382,18 +388,18 @@ export function init(width, height, options) {
|
|
|
382
388
|
* @function video.createCanvas
|
|
383
389
|
* @param {number} width width
|
|
384
390
|
* @param {number} height height
|
|
385
|
-
* @param {boolean} [
|
|
391
|
+
* @param {boolean} [returnOffscreenCanvas=false] will return an OffscreenCanvas if supported
|
|
386
392
|
* @returns {HTMLCanvasElement|OffscreenCanvas}
|
|
387
393
|
*/
|
|
388
|
-
export function createCanvas(width, height,
|
|
394
|
+
export function createCanvas(width, height, returnOffscreenCanvas = false) {
|
|
389
395
|
var _canvas;
|
|
390
396
|
|
|
391
397
|
if (width === 0 || height === 0) {
|
|
392
398
|
throw new Error("width or height was zero, Canvas could not be initialized !");
|
|
393
399
|
}
|
|
394
400
|
|
|
395
|
-
if (device.
|
|
396
|
-
_canvas = new OffscreenCanvas(0, 0);
|
|
401
|
+
if (device.offscreenCanvas === true && returnOffscreenCanvas === true) {
|
|
402
|
+
_canvas = new globalThis.OffscreenCanvas(0, 0);
|
|
397
403
|
// stubbing style for compatibility,
|
|
398
404
|
// as OffscreenCanvas is detached from the DOM
|
|
399
405
|
if (typeof _canvas.style === "undefined") {
|
|
@@ -448,5 +454,5 @@ export function scale(x, y) {
|
|
|
448
454
|
renderer.setBlendMode(settings.blendMode, context);
|
|
449
455
|
|
|
450
456
|
// force repaint
|
|
451
|
-
repaint();
|
|
457
|
+
game.repaint();
|
|
452
458
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as event from "./../../system/event.js";
|
|
2
|
-
import device from "./../../system/device.js";
|
|
2
|
+
import * as device from "./../../system/device.js";
|
|
3
3
|
import { extractUniforms } from "./utils/uniforms.js";
|
|
4
4
|
import { extractAttributes } from "./utils/attributes.js";
|
|
5
5
|
import { compileProgram } from "./utils/program.js";
|
|
@@ -20,7 +20,7 @@ class WebGLRenderer extends Renderer {
|
|
|
20
20
|
* @param {number} options.width The width of the canvas without scaling
|
|
21
21
|
* @param {number} options.height The height of the canvas without scaling
|
|
22
22
|
* @param {HTMLCanvasElement} [options.canvas] The html canvas to draw to on screen
|
|
23
|
-
* @param {boolean} [options.doubleBuffering=false] Whether to enable double buffering
|
|
23
|
+
* @param {boolean} [options.doubleBuffering=false] Whether to enable double buffering (not applicable when using the WebGL Renderer)
|
|
24
24
|
* @param {boolean} [options.antiAlias=false] Whether to enable anti-aliasing
|
|
25
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
26
|
* @param {boolean} [options.transparent=false] Whether to enable transparency on the canvas (performance hit when enabled)
|