melonjs 10.7.0 → 10.9.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/dist/melonjs.js +1488 -666
- package/dist/melonjs.min.js +4 -4
- package/dist/melonjs.module.d.ts +929 -202
- package/dist/melonjs.module.js +1575 -777
- package/package.json +9 -9
- package/src/camera/camera2d.js +1 -1
- package/src/entity/entity.js +6 -7
- package/src/geometries/ellipse.js +10 -11
- package/src/geometries/line.js +3 -3
- package/src/geometries/path2d.js +319 -0
- package/src/geometries/poly.js +11 -11
- package/src/geometries/rectangle.js +15 -15
- package/src/geometries/roundrect.js +164 -0
- package/src/index.js +5 -1
- package/src/input/gamepad.js +2 -2
- package/src/input/pointerevent.js +1 -1
- package/src/lang/deprecated.js +1 -1
- package/src/level/tiled/TMXLayer.js +1 -1
- package/src/level/tiled/TMXObject.js +9 -12
- package/src/level/tiled/TMXTileMap.js +23 -4
- package/src/level/tiled/renderer/TMXHexagonalRenderer.js +1 -1
- package/src/level/tiled/renderer/TMXIsometricRenderer.js +1 -1
- package/src/level/tiled/renderer/TMXOrthogonalRenderer.js +1 -1
- package/src/level/tiled/renderer/TMXRenderer.js +1 -1
- package/src/level/tiled/renderer/TMXStaggeredRenderer.js +1 -1
- package/src/loader/loader.js +4 -4
- package/src/loader/loadingscreen.js +1 -1
- package/src/math/color.js +1 -1
- package/src/math/matrix2.js +1 -1
- package/src/math/matrix3.js +1 -1
- package/src/math/observable_vector2.js +1 -1
- package/src/math/observable_vector3.js +1 -1
- package/src/math/vector2.js +1 -1
- package/src/math/vector3.js +1 -1
- package/src/particles/emitter.js +23 -14
- package/src/particles/particle.js +3 -2
- package/src/physics/body.js +67 -51
- package/src/physics/bounds.js +8 -9
- package/src/physics/world.js +1 -1
- package/src/polyfill/index.js +1 -0
- package/src/polyfill/roundrect.js +235 -0
- package/src/renderable/collectable.js +9 -2
- package/src/renderable/colorlayer.js +1 -1
- package/src/renderable/container.js +1 -1
- package/src/renderable/imagelayer.js +1 -1
- package/src/renderable/renderable.js +2 -2
- package/src/renderable/sprite.js +2 -3
- package/src/renderable/trigger.js +10 -4
- package/src/state/stage.js +1 -1
- package/src/state/state.js +1 -1
- package/src/system/device.js +10 -8
- package/src/system/pooling.js +156 -149
- package/src/text/bitmaptext.js +1 -1
- package/src/text/text.js +1 -1
- package/src/utils/utils.js +2 -2
- package/src/video/canvas/canvas_renderer.js +83 -39
- package/src/video/renderer.js +36 -16
- package/src/video/texture.js +1 -1
- package/src/video/webgl/glshader.js +29 -193
- package/src/video/webgl/utils/attributes.js +16 -0
- package/src/video/webgl/utils/precision.js +11 -0
- package/src/video/webgl/utils/program.js +58 -0
- package/src/video/webgl/utils/string.js +16 -0
- package/src/video/webgl/utils/uniforms.js +87 -0
- package/src/video/webgl/webgl_compositor.js +1 -14
- package/src/video/webgl/webgl_renderer.js +124 -182
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import Rect from "./rectangle.js";
|
|
2
|
+
|
|
3
|
+
// https://developer.chrome.com/blog/canvas2d/#round-rect
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @classdesc
|
|
7
|
+
* a rectangle object with rounded corners
|
|
8
|
+
* @augments Rect
|
|
9
|
+
*/
|
|
10
|
+
class RoundRect extends Rect {
|
|
11
|
+
/**
|
|
12
|
+
* @param {number} x position of the rounded rectangle
|
|
13
|
+
* @param {number} y position of the rounded rectangle
|
|
14
|
+
* @param {number} width the rectangle width
|
|
15
|
+
* @param {number} height the rectangle height
|
|
16
|
+
* @param {number} [radius=20] the radius of the rounded corner
|
|
17
|
+
*/
|
|
18
|
+
constructor(x, y, width, height, radius = 20) {
|
|
19
|
+
// parent constructor
|
|
20
|
+
super(x, y, width, height);
|
|
21
|
+
|
|
22
|
+
// set the corner radius
|
|
23
|
+
this.radius = radius;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** @ignore */
|
|
27
|
+
onResetEvent(x, y, w, h, radius) {
|
|
28
|
+
super.setShape(x, y, w, h);
|
|
29
|
+
this.radius = radius;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* the radius of the rounded corner
|
|
35
|
+
* @public
|
|
36
|
+
* @type {number}
|
|
37
|
+
* @default 20
|
|
38
|
+
* @name radius
|
|
39
|
+
* @memberof RoundRect.prototype
|
|
40
|
+
*/
|
|
41
|
+
get radius() {
|
|
42
|
+
return this._radius;
|
|
43
|
+
}
|
|
44
|
+
set radius(value) {
|
|
45
|
+
// verify the rectangle is at least as wide and tall as the rounded corners.
|
|
46
|
+
if (this.width < 2 * value) {
|
|
47
|
+
value = this.width / 2;
|
|
48
|
+
}
|
|
49
|
+
if (this.height < 2 * value) {
|
|
50
|
+
value = this.height / 2;
|
|
51
|
+
}
|
|
52
|
+
this._radius = value;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* copy the position, size and radius of the given rounded rectangle into this one
|
|
57
|
+
* @name copy
|
|
58
|
+
* @memberof RoundRect.prototype
|
|
59
|
+
* @function
|
|
60
|
+
* @param {RoundRect} rrect source rounded rectangle
|
|
61
|
+
* @returns {RoundRect} new rectangle
|
|
62
|
+
*/
|
|
63
|
+
copy(rrect) {
|
|
64
|
+
super.setShape(rrect.pos.x, rrect.pos.y, rrect.width, rrect.height);
|
|
65
|
+
this.radius = rrect.radius;
|
|
66
|
+
return this;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Returns true if the rounded rectangle contains the given point
|
|
71
|
+
* @name contains
|
|
72
|
+
* @memberof RoundRect.prototype
|
|
73
|
+
* @function
|
|
74
|
+
* @param {number} x x coordinate
|
|
75
|
+
* @param {number} y y coordinate
|
|
76
|
+
* @returns {boolean} true if contains
|
|
77
|
+
*/
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Returns true if the rounded rectangle contains the given point
|
|
81
|
+
* @name contains
|
|
82
|
+
* @memberof RoundRect.prototype
|
|
83
|
+
* @function
|
|
84
|
+
* @param {Vector2d} point
|
|
85
|
+
* @returns {boolean} true if contains
|
|
86
|
+
*/
|
|
87
|
+
contains() {
|
|
88
|
+
var arg0 = arguments[0];
|
|
89
|
+
var _x, _y;
|
|
90
|
+
if (arguments.length === 2) {
|
|
91
|
+
// x, y
|
|
92
|
+
_x = arg0;
|
|
93
|
+
_y = arguments[1];
|
|
94
|
+
} else {
|
|
95
|
+
if (arg0 instanceof Rect) {
|
|
96
|
+
// good enough
|
|
97
|
+
return super.contains(arg0);
|
|
98
|
+
} else {
|
|
99
|
+
// vector
|
|
100
|
+
_x = arg0.x;
|
|
101
|
+
_y = arg0.y;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// check whether point is outside the bounding box
|
|
106
|
+
if (_x < this.left || _x >= this.right || _y < this.top || _y >= this.bottom) {
|
|
107
|
+
return false; // outside bounding box
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// check whether point is within the bounding box minus radius
|
|
111
|
+
if ((_x >= this.left + this.radius && _x <= this.right - this.radius) || (_y >= this.top + this.radius && _y <= this.bottom - this.radius)) {
|
|
112
|
+
return true;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// check whether point is in one of the rounded corner areas
|
|
116
|
+
var tx, ty;
|
|
117
|
+
var radiusX = Math.max(0, Math.min(this.radius, this.width / 2));
|
|
118
|
+
var radiusY = Math.max(0, Math.min(this.radius, this.height / 2));
|
|
119
|
+
|
|
120
|
+
if (_x < this.left + radiusX && _y < this.top + radiusY) {
|
|
121
|
+
tx = _x - this.left - radiusX;
|
|
122
|
+
ty = _y - this.top - radiusY;
|
|
123
|
+
} else if (_x > this.right - radiusX && _y < this.top + radiusY) {
|
|
124
|
+
tx = _x - this.right + radiusX;
|
|
125
|
+
ty = _y - this.top - radiusY;
|
|
126
|
+
} else if (_x > this.right - radiusX && _y > this.bottom - radiusY) {
|
|
127
|
+
tx = _x - this.right + radiusX;
|
|
128
|
+
ty = _y - this.bottom + radiusY;
|
|
129
|
+
} else if (_x < this.left + radiusX && _y > this.bottom - radiusY) {
|
|
130
|
+
tx = _x - this.left - radiusX;
|
|
131
|
+
ty = _y - this.bottom + radiusY;
|
|
132
|
+
} else {
|
|
133
|
+
return false; // inside and not within the rounded corner area
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// Pythagorean theorem.
|
|
137
|
+
return ((tx * tx) + (ty * ty) <= (radiusX * radiusY));
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* check if this RoundRect is identical to the specified one
|
|
142
|
+
* @name equals
|
|
143
|
+
* @memberof RoundRect.prototype
|
|
144
|
+
* @function
|
|
145
|
+
* @param {RoundRect} rrect
|
|
146
|
+
* @returns {boolean} true if equals
|
|
147
|
+
*/
|
|
148
|
+
equals(rrect) {
|
|
149
|
+
return super.equals(rrect) && this.radius === rrect.radius;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* clone this RoundRect
|
|
154
|
+
* @name clone
|
|
155
|
+
* @memberof RoundRect.prototype
|
|
156
|
+
* @function
|
|
157
|
+
* @returns {RoundRect} new RoundRect
|
|
158
|
+
*/
|
|
159
|
+
clone() {
|
|
160
|
+
return new RoundRect(this.pos.x, this.pos.y, this.width, this.height, radius);
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
export default RoundRect;
|
package/src/index.js
CHANGED
|
@@ -15,7 +15,7 @@ import { plugin, plugins } from "./plugin/plugin.js";
|
|
|
15
15
|
import * as video from "./video/video.js";
|
|
16
16
|
import save from "./system/save.js";
|
|
17
17
|
import timer from "./system/timer.js";
|
|
18
|
-
import
|
|
18
|
+
import pool from "./system/pooling.js";
|
|
19
19
|
import state from "./state/state.js";
|
|
20
20
|
import level from "./level/level.js";
|
|
21
21
|
|
|
@@ -31,6 +31,7 @@ import Polygon from "./geometries/poly.js";
|
|
|
31
31
|
import Line from "./geometries/line.js";
|
|
32
32
|
import Ellipse from "./geometries/ellipse.js";
|
|
33
33
|
import Rect from "./geometries/rectangle.js";
|
|
34
|
+
import RoundRect from "./geometries/roundrect.js";
|
|
34
35
|
import QuadTree from "./physics/quadtree.js";
|
|
35
36
|
import Body from "./physics/body.js";
|
|
36
37
|
import Bounds from "./physics/bounds.js";
|
|
@@ -117,6 +118,7 @@ export {
|
|
|
117
118
|
Line,
|
|
118
119
|
Ellipse,
|
|
119
120
|
Rect,
|
|
121
|
+
RoundRect,
|
|
120
122
|
Tween,
|
|
121
123
|
QuadTree,
|
|
122
124
|
GLShader,
|
|
@@ -218,6 +220,7 @@ export function boot() {
|
|
|
218
220
|
pool.register("me.Matrix2d", Matrix2d, true);
|
|
219
221
|
pool.register("me.Matrix3d", Matrix3d, true);
|
|
220
222
|
pool.register("me.Rect", Rect, true);
|
|
223
|
+
pool.register("me.RoundRect", RoundRect, true);
|
|
221
224
|
pool.register("me.Polygon", Polygon, true);
|
|
222
225
|
pool.register("me.Line", Line, true);
|
|
223
226
|
pool.register("me.Ellipse", Ellipse, true);
|
|
@@ -245,6 +248,7 @@ export function boot() {
|
|
|
245
248
|
pool.register("Matrix2d", Matrix2d, true);
|
|
246
249
|
pool.register("Matrix3d", Matrix3d, true);
|
|
247
250
|
pool.register("Rect", Rect, true);
|
|
251
|
+
pool.register("RoundRect", RoundRect, true);
|
|
248
252
|
pool.register("Polygon", Polygon, true);
|
|
249
253
|
pool.register("Line", Line, true);
|
|
250
254
|
pool.register("Ellipse", Ellipse, true);
|
package/src/input/gamepad.js
CHANGED
|
@@ -57,8 +57,8 @@ var leadingZeroRE = /^0+/;
|
|
|
57
57
|
function addMapping(id, mapping) {
|
|
58
58
|
var expanded_id = id.replace(vendorProductRE, function (_, a, b) {
|
|
59
59
|
return (
|
|
60
|
-
"000".
|
|
61
|
-
"000".
|
|
60
|
+
"000".slice(a.length - 1) + a + "-" +
|
|
61
|
+
"000".slice(b.length - 1) + b + "-"
|
|
62
62
|
);
|
|
63
63
|
});
|
|
64
64
|
var sparse_id = id.replace(vendorProductRE, function (_, a, b) {
|
|
@@ -5,7 +5,7 @@ import { throttle } from "./../utils/function.js";
|
|
|
5
5
|
import { remove } from "./../utils/array.js";
|
|
6
6
|
import * as event from "./../system/event.js";
|
|
7
7
|
import timer from "./../system/timer.js";
|
|
8
|
-
import
|
|
8
|
+
import pool from "./../system/pooling.js";
|
|
9
9
|
import device from "./../system/device.js";
|
|
10
10
|
import Pointer from "./pointer.js";
|
|
11
11
|
import Rect from "./../geometries/rectangle.js";
|
package/src/lang/deprecated.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createCanvas } from "./../../video/video.js";
|
|
2
|
-
import
|
|
2
|
+
import pool from "./../../system/pooling.js";
|
|
3
3
|
import * as TMXUtils from "./TMXUtils.js";
|
|
4
4
|
import Tile from "./TMXTile.js";
|
|
5
5
|
import Renderable from "./../../renderable/renderable.js";
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import pool from "./../../system/pooling.js";
|
|
2
2
|
import { applyTMXProperties } from "./TMXUtils.js";
|
|
3
3
|
import Tile from "./TMXTile.js";
|
|
4
|
-
import Ellipse from "./../../geometries/ellipse.js";
|
|
5
|
-
import Polygon from "./../../geometries/poly.js";
|
|
6
|
-
import Line from "./../../geometries/line.js";
|
|
7
4
|
import { degToRad } from "./../../math/math.js";
|
|
8
5
|
|
|
9
6
|
/**
|
|
@@ -260,7 +257,7 @@ export default class TMXObject {
|
|
|
260
257
|
// add an ellipse shape
|
|
261
258
|
if (this.isEllipse === true) {
|
|
262
259
|
// ellipse coordinates are the center position, so set default to the corresonding radius
|
|
263
|
-
shapes.push((
|
|
260
|
+
shapes.push((pool.pull("Ellipse",
|
|
264
261
|
this.width / 2,
|
|
265
262
|
this.height / 2,
|
|
266
263
|
this.width,
|
|
@@ -270,7 +267,7 @@ export default class TMXObject {
|
|
|
270
267
|
|
|
271
268
|
// add a polygon
|
|
272
269
|
if (this.isPolygon === true) {
|
|
273
|
-
var _polygon =
|
|
270
|
+
var _polygon = pool.pull("Polygon", 0, 0, this.points);
|
|
274
271
|
// make sure it's a convex polygon
|
|
275
272
|
if (_polygon.isConvex() === false ) {
|
|
276
273
|
throw new Error("collision polygones in Tiled should be defined as Convex");
|
|
@@ -286,22 +283,22 @@ export default class TMXObject {
|
|
|
286
283
|
for (i = 0; i < segments; i++) {
|
|
287
284
|
// clone the value before, as [i + 1]
|
|
288
285
|
// is reused later by the next segment
|
|
289
|
-
p1 =
|
|
290
|
-
p2 =
|
|
286
|
+
p1 = pool.pull("Vector2d", p[i].x, p[i].y);
|
|
287
|
+
p2 = pool.pull("Vector2d", p[i + 1].x, p[i + 1].y);
|
|
291
288
|
if (this.rotation !== 0) {
|
|
292
289
|
p1 = p1.rotate(this.rotation);
|
|
293
290
|
p2 = p2.rotate(this.rotation);
|
|
294
291
|
}
|
|
295
|
-
shapes.push(
|
|
292
|
+
shapes.push(pool.pull("Line", 0, 0, [ p1, p2 ]));
|
|
296
293
|
}
|
|
297
294
|
}
|
|
298
295
|
|
|
299
296
|
// it's a rectangle, returns a polygon object anyway
|
|
300
297
|
else {
|
|
301
|
-
shapes.push((
|
|
298
|
+
shapes.push((pool.pull("Polygon",
|
|
302
299
|
0, 0, [
|
|
303
|
-
|
|
304
|
-
|
|
300
|
+
pool.pull("Vector2d"), pool.pull("Vector2d", this.width, 0),
|
|
301
|
+
pool.pull("Vector2d", this.width, this.height), pool.pull("Vector2d", 0, this.height)
|
|
305
302
|
]
|
|
306
303
|
)).rotate(this.rotation));
|
|
307
304
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import pool from "./../../system/pooling.js";
|
|
2
2
|
import * as event from "./../../system/event.js";
|
|
3
3
|
import { viewport } from "./../../game.js";
|
|
4
4
|
import collision from "./../../physics/collision.js";
|
|
@@ -14,7 +14,6 @@ import TMXLayer from "./TMXLayer.js";
|
|
|
14
14
|
import { applyTMXProperties } from "./TMXUtils.js";
|
|
15
15
|
import Renderable from "./../../renderable/renderable.js";
|
|
16
16
|
import Container from "./../../renderable/container.js";
|
|
17
|
-
import Rect from "./../../geometries/rectangle.js";
|
|
18
17
|
|
|
19
18
|
// constant to identify the collision object layer
|
|
20
19
|
var COLLISION_GROUP = "collision";
|
|
@@ -474,6 +473,8 @@ class TMXTileMap {
|
|
|
474
473
|
var settings = group.objects[o];
|
|
475
474
|
// reference to the instantiated object
|
|
476
475
|
var obj;
|
|
476
|
+
// a reference to the default shape
|
|
477
|
+
var shape;
|
|
477
478
|
|
|
478
479
|
// Tiled uses 0,0 by default
|
|
479
480
|
if (typeof (settings.anchorPoint) === "undefined") {
|
|
@@ -506,9 +507,18 @@ class TMXTileMap {
|
|
|
506
507
|
// set the obj z order
|
|
507
508
|
obj.pos.z = settings.z;
|
|
508
509
|
} else if (typeof settings.tile === "object") {
|
|
510
|
+
// create a default shape if none is specified
|
|
511
|
+
shape = settings.shapes;
|
|
512
|
+
if (typeof shape === "undefined") {
|
|
513
|
+
shape = pool.pull("Polygon", 0, 0, [
|
|
514
|
+
pool.pull("Vector2d", 0, 0),
|
|
515
|
+
pool.pull("Vector2d", this.width, 0),
|
|
516
|
+
pool.pull("Vector2d", this.width, this.height)
|
|
517
|
+
]);
|
|
518
|
+
}
|
|
509
519
|
// check if a me.Tile object is embedded
|
|
510
520
|
obj = settings.tile.getRenderable(settings);
|
|
511
|
-
obj.body = new Body(obj,
|
|
521
|
+
obj.body = new Body(obj, shape);
|
|
512
522
|
obj.body.setStatic(true);
|
|
513
523
|
// set the obj z order
|
|
514
524
|
obj.pos.setMuted(settings.x, settings.y, settings.z);
|
|
@@ -527,11 +537,20 @@ class TMXTileMap {
|
|
|
527
537
|
settings.x, settings.y,
|
|
528
538
|
settings.width, settings.height
|
|
529
539
|
);
|
|
540
|
+
// create a default shape if none is specified
|
|
541
|
+
shape = settings.shapes;
|
|
542
|
+
if (typeof shape === "undefined") {
|
|
543
|
+
shape = pool.pull("Polygon", 0, 0, [
|
|
544
|
+
pool.pull("Vector2d", 0, 0),
|
|
545
|
+
pool.pull("Vector2d", this.width, 0),
|
|
546
|
+
pool.pull("Vector2d", this.width, this.height)
|
|
547
|
+
]);
|
|
548
|
+
}
|
|
530
549
|
obj.anchorPoint.set(0, 0);
|
|
531
550
|
obj.name = settings.name;
|
|
532
551
|
obj.type = settings.type;
|
|
533
552
|
obj.id = settings.id;
|
|
534
|
-
obj.body = new Body(obj,
|
|
553
|
+
obj.body = new Body(obj, shape);
|
|
535
554
|
obj.body.setStatic(true);
|
|
536
555
|
obj.resize(obj.body.getBounds().width, obj.body.getBounds().height);
|
|
537
556
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Vector2d from "./../../../math/vector2.js";
|
|
2
|
-
import
|
|
2
|
+
import pool from "./../../../system/pooling.js";
|
|
3
3
|
import TMXHexagonalRenderer from "./TMXHexagonalRenderer.js";
|
|
4
4
|
import { degToRad } from "./../../../math/math.js";
|
|
5
5
|
|
package/src/loader/loader.js
CHANGED
|
@@ -46,7 +46,7 @@ function checkLoadStatus(onload) {
|
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
else {
|
|
49
|
-
timerId = setTimeout(
|
|
49
|
+
timerId = setTimeout(() => {
|
|
50
50
|
checkLoadStatus(onload);
|
|
51
51
|
}, 100);
|
|
52
52
|
}
|
|
@@ -85,7 +85,7 @@ function preloadImage(img, onload, onerror) {
|
|
|
85
85
|
function preloadFontFace(data, onload, onerror) {
|
|
86
86
|
var font = new FontFace(data.name, data.src);
|
|
87
87
|
// loading promise
|
|
88
|
-
font.load().then(
|
|
88
|
+
font.load().then(() => {
|
|
89
89
|
// apply the font after the font has finished downloading
|
|
90
90
|
document.fonts.add(font);
|
|
91
91
|
document.body.style.fontFamily = data.name;
|
|
@@ -278,12 +278,12 @@ function preloadJavascript(data, onload, onerror) {
|
|
|
278
278
|
}
|
|
279
279
|
script.defer = true;
|
|
280
280
|
|
|
281
|
-
script.onload =
|
|
281
|
+
script.onload = () => {
|
|
282
282
|
// callback
|
|
283
283
|
onload();
|
|
284
284
|
};
|
|
285
285
|
|
|
286
|
-
script.onerror =
|
|
286
|
+
script.onerror = () => {
|
|
287
287
|
// callback
|
|
288
288
|
onerror(data.name);
|
|
289
289
|
};
|
|
@@ -2,7 +2,7 @@ import { world, viewport } from "./../game.js";
|
|
|
2
2
|
import { createCanvas, renderer } from "./../video/video.js";
|
|
3
3
|
import * as event from "./../system/event.js";
|
|
4
4
|
import {nextPowerOfTwo} from "./../math/math.js";
|
|
5
|
-
import
|
|
5
|
+
import pool from "./../system/pooling.js";
|
|
6
6
|
import Renderable from "./../renderable/renderable.js";
|
|
7
7
|
import Stage from "./../state/stage.js";
|
|
8
8
|
|
package/src/math/color.js
CHANGED
package/src/math/matrix2.js
CHANGED
package/src/math/matrix3.js
CHANGED
package/src/math/vector2.js
CHANGED
package/src/math/vector3.js
CHANGED
package/src/particles/emitter.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createCanvas } from "./../video/video.js";
|
|
2
|
-
import
|
|
2
|
+
import pool from "./../system/pooling.js";
|
|
3
3
|
import ParticleEmitterSettings from "./settings.js";
|
|
4
4
|
import { randomFloat } from "./../math/math.js";
|
|
5
5
|
import Container from "./../renderable/container.js";
|
|
@@ -32,14 +32,17 @@ class ParticleEmitter extends Container {
|
|
|
32
32
|
* @param {number} y y position of the particle emitter
|
|
33
33
|
* @param {ParticleEmitterSettings} [settings=ParticleEmitterSettings] the settings for the particle emitter.
|
|
34
34
|
* @example
|
|
35
|
-
* // Create a
|
|
36
|
-
* var emitter = new ParticleEmitter(100, 100
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
35
|
+
* // Create a particle emitter at position 100, 100
|
|
36
|
+
* var emitter = new ParticleEmitter(100, 100, {
|
|
37
|
+
* width: 16,
|
|
38
|
+
* height : 16,
|
|
39
|
+
* tint: "#f00",
|
|
40
|
+
* totalParticles: 32,
|
|
41
|
+
* angle: 0,
|
|
42
|
+
* angleVariation: 6.283185307179586,
|
|
43
|
+
* maxLife: 5,
|
|
44
|
+
* speed: 3
|
|
45
|
+
* });
|
|
43
46
|
*
|
|
44
47
|
* // Add the emitter to the game world
|
|
45
48
|
* me.game.world.addChild(emitter);
|
|
@@ -62,6 +65,15 @@ class ParticleEmitter extends Container {
|
|
|
62
65
|
settings.height | 1
|
|
63
66
|
);
|
|
64
67
|
|
|
68
|
+
/**
|
|
69
|
+
* the current (active) emitter settings
|
|
70
|
+
* @public
|
|
71
|
+
* @type {ParticleEmitterSettings}
|
|
72
|
+
* @name settings
|
|
73
|
+
* @memberof ParticleEmitter
|
|
74
|
+
*/
|
|
75
|
+
this.settings = {};
|
|
76
|
+
|
|
65
77
|
// center the emitter around the given coordinates
|
|
66
78
|
this.centerOn(x, y);
|
|
67
79
|
|
|
@@ -92,9 +104,6 @@ class ParticleEmitter extends Container {
|
|
|
92
104
|
// count the updates
|
|
93
105
|
this._updateCount = 0;
|
|
94
106
|
|
|
95
|
-
// the emitter settings
|
|
96
|
-
this.settings = {};
|
|
97
|
-
|
|
98
107
|
// internally store how much time was skipped when frames are skipped
|
|
99
108
|
this._dt = 0;
|
|
100
109
|
|
|
@@ -106,7 +115,7 @@ class ParticleEmitter extends Container {
|
|
|
106
115
|
|
|
107
116
|
/**
|
|
108
117
|
* Reset the emitter with particle emitter settings.
|
|
109
|
-
* @param {
|
|
118
|
+
* @param {ParticleEmitterSettings} settings [optional] object with emitter settings. See {@link ParticleEmitterSettings}
|
|
110
119
|
*/
|
|
111
120
|
reset(settings = {}) {
|
|
112
121
|
Object.assign(this.settings, ParticleEmitterSettings, settings);
|
|
@@ -140,7 +149,7 @@ class ParticleEmitter extends Container {
|
|
|
140
149
|
// Add count particles in the game world
|
|
141
150
|
/** @ignore */
|
|
142
151
|
addParticles(count) {
|
|
143
|
-
for (var i = 0; i <
|
|
152
|
+
for (var i = 0; i < count; i++) {
|
|
144
153
|
// Add particle to the container
|
|
145
154
|
this.addChild(pool.pull("Particle", this), this.pos.z);
|
|
146
155
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import pool from "./../system/pooling.js";
|
|
2
2
|
import timer from "./../system/timer.js";
|
|
3
3
|
import { randomFloat, clamp } from "./../math/math.js";
|
|
4
4
|
import Renderable from "./../renderable/renderable.js";
|
|
@@ -36,9 +36,10 @@ class Particle extends Renderable {
|
|
|
36
36
|
emitter.settings.image.width,
|
|
37
37
|
emitter.settings.image.height
|
|
38
38
|
);
|
|
39
|
+
this.currentTransform.identity();
|
|
39
40
|
} else {
|
|
40
41
|
// particle velocity
|
|
41
|
-
this.vel =
|
|
42
|
+
this.vel = pool.pull("Vector2d");
|
|
42
43
|
}
|
|
43
44
|
|
|
44
45
|
this.image = emitter.settings.image;
|