melonjs 10.2.3 → 10.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -6
- package/dist/melonjs.js +3620 -3582
- package/dist/melonjs.min.js +5 -5
- package/dist/melonjs.module.d.ts +3646 -4545
- package/dist/melonjs.module.js +3912 -3521
- package/package.json +21 -20
- package/src/audio/audio.js +30 -31
- package/src/camera/camera2d.js +47 -58
- package/src/entity/entity.js +32 -38
- package/src/game.js +21 -22
- package/src/{shapes → geometries}/ellipse.js +40 -47
- package/src/{shapes → geometries}/line.js +9 -12
- package/src/{shapes → geometries}/poly.js +100 -53
- package/src/{shapes → geometries}/rectangle.js +42 -45
- package/src/index.js +14 -32
- package/src/input/gamepad.js +11 -10
- package/src/input/input.js +2 -3
- package/src/input/keyboard.js +113 -113
- package/src/input/pointer.js +61 -29
- package/src/input/pointerevent.js +92 -29
- package/src/lang/deprecated.js +83 -13
- package/src/level/level.js +23 -24
- package/src/level/tiled/TMXGroup.js +7 -9
- package/src/level/tiled/TMXLayer.js +30 -33
- package/src/level/tiled/TMXObject.js +59 -53
- package/src/level/tiled/TMXTile.js +18 -19
- package/src/level/tiled/TMXTileMap.js +40 -46
- package/src/level/tiled/TMXTileset.js +12 -16
- package/src/level/tiled/TMXTilesetGroup.js +9 -10
- package/src/level/tiled/renderer/TMXHexagonalRenderer.js +7 -9
- package/src/level/tiled/renderer/TMXIsometricRenderer.js +7 -9
- package/src/level/tiled/renderer/TMXOrthogonalRenderer.js +4 -6
- package/src/level/tiled/renderer/TMXRenderer.js +24 -26
- package/src/level/tiled/renderer/TMXStaggeredRenderer.js +1 -5
- package/src/loader/loader.js +17 -16
- package/src/loader/loadingscreen.js +2 -5
- package/src/math/color.js +47 -67
- package/src/math/math.js +15 -16
- package/src/math/matrix2.js +53 -59
- package/src/math/matrix3.js +56 -63
- package/src/math/observable_vector2.js +87 -77
- package/src/math/observable_vector3.js +97 -80
- package/src/math/vector2.js +107 -97
- package/src/math/vector3.js +116 -100
- package/src/particles/emitter.js +66 -76
- package/src/particles/particle.js +4 -6
- package/src/particles/particlecontainer.js +2 -4
- package/src/physics/body.js +49 -147
- package/src/physics/bounds.js +48 -50
- package/src/physics/collision.js +13 -14
- package/src/physics/detector.js +18 -17
- package/src/physics/quadtree.js +17 -20
- package/src/physics/sat.js +30 -30
- package/src/physics/world.js +24 -29
- package/src/plugin/plugin.js +11 -15
- package/src/renderable/GUI.js +41 -47
- package/src/renderable/collectable.js +5 -10
- package/src/renderable/colorlayer.js +10 -15
- package/src/renderable/container.js +87 -73
- package/src/renderable/dragndrop.js +224 -0
- package/src/renderable/imagelayer.js +25 -32
- package/src/renderable/nineslicesprite.js +41 -42
- package/src/renderable/renderable.js +113 -124
- package/src/renderable/sprite.js +62 -69
- package/src/renderable/trigger.js +26 -32
- package/src/state/stage.js +13 -18
- package/src/state/state.js +26 -27
- package/src/system/device.js +76 -133
- package/src/system/event.js +81 -70
- package/src/system/pooling.js +11 -12
- package/src/system/save.js +3 -4
- package/src/system/timer.js +19 -20
- package/src/text/bitmaptext.js +57 -55
- package/src/text/bitmaptextdata.js +10 -11
- package/src/text/glyph.js +3 -0
- package/src/text/text.js +49 -55
- package/src/tweens/easing.js +1 -1
- package/src/tweens/interpolation.js +1 -1
- package/src/tweens/tween.js +44 -46
- package/src/utils/agent.js +3 -4
- package/src/utils/array.js +4 -5
- package/src/utils/file.js +3 -4
- package/src/utils/function.js +4 -5
- package/src/utils/string.js +7 -9
- package/src/utils/utils.js +4 -5
- package/src/video/canvas/canvas_renderer.js +60 -62
- package/src/video/renderer.js +53 -58
- package/src/video/texture.js +98 -112
- package/src/video/texture_cache.js +26 -10
- package/src/video/video.js +15 -16
- package/src/video/webgl/buffer/vertex.js +2 -2
- package/src/video/webgl/glshader.js +37 -39
- package/src/video/webgl/webgl_compositor.js +128 -101
- package/src/video/webgl/webgl_renderer.js +126 -106
- package/src/entity/draggable.js +0 -139
- package/src/entity/droptarget.js +0 -109
package/src/physics/sat.js
CHANGED
|
@@ -26,7 +26,7 @@ var RIGHT_VORNOI_REGION = 1;
|
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
28
|
* A pool of `Vector` objects that are used in calculations to avoid allocating memory.
|
|
29
|
-
* @type {Array.<
|
|
29
|
+
* @type {Array.<Vector2d>}
|
|
30
30
|
* @ignore
|
|
31
31
|
*/
|
|
32
32
|
var T_VECTORS = [];
|
|
@@ -46,8 +46,8 @@ for (var a = 0; a < 5; a++) { T_ARRAYS.push([]); }
|
|
|
46
46
|
* resulting in a one dimensional range of the minimum and
|
|
47
47
|
* maximum value on that axis.
|
|
48
48
|
* @ignore
|
|
49
|
-
* @param {Array.<
|
|
50
|
-
* @param {
|
|
49
|
+
* @param {Array.<Vector2d>} points The points to flatten.
|
|
50
|
+
* @param {Vector2d} normal The unit vector axis to flatten on.
|
|
51
51
|
* @param {Array.<number>} result An array. After calling this function,
|
|
52
52
|
* result[0] will be the minimum value,
|
|
53
53
|
* result[1] will be the maximum value.
|
|
@@ -58,7 +58,7 @@ function flattenPointsOn(points, normal, result) {
|
|
|
58
58
|
var len = points.length;
|
|
59
59
|
for (var i = 0; i < len; i++) {
|
|
60
60
|
// The magnitude of the projection of the point onto the normal
|
|
61
|
-
var dot = points[i].
|
|
61
|
+
var dot = points[i].dot(normal);
|
|
62
62
|
if (dot < min) { min = dot; }
|
|
63
63
|
if (dot > max) { max = dot; }
|
|
64
64
|
}
|
|
@@ -70,11 +70,11 @@ function flattenPointsOn(points, normal, result) {
|
|
|
70
70
|
* Check whether two convex polygons are separated by the specified
|
|
71
71
|
* axis (must be a unit vector).
|
|
72
72
|
* @ignore
|
|
73
|
-
* @param {
|
|
74
|
-
* @param {
|
|
75
|
-
* @param {Array.<
|
|
76
|
-
* @param {Array.<
|
|
77
|
-
* @param {
|
|
73
|
+
* @param {Vector2d} aPos The position of the first polygon.
|
|
74
|
+
* @param {Vector2d} bPos The position of the second polygon.
|
|
75
|
+
* @param {Array.<Vector2d>} aPoints The points in the first polygon.
|
|
76
|
+
* @param {Array.<Vector2d>} bPoints The points in the second polygon.
|
|
77
|
+
* @param {Vector2d} axis The axis (unit sized) to test against. The points of both polygons
|
|
78
78
|
* will be projected onto this axis.
|
|
79
79
|
* @param {Response=} response A Response object (optional) which will be populated
|
|
80
80
|
* if the axis is not a separating axis.
|
|
@@ -87,7 +87,7 @@ function isSeparatingAxis(aPos, bPos, aPoints, bPoints, axis, response) {
|
|
|
87
87
|
var rangeB = T_ARRAYS.pop();
|
|
88
88
|
// The magnitude of the offset between the two polygons
|
|
89
89
|
var offsetV = T_VECTORS.pop().copy(bPos).sub(aPos);
|
|
90
|
-
var projectedOffset = offsetV.
|
|
90
|
+
var projectedOffset = offsetV.dot(axis);
|
|
91
91
|
|
|
92
92
|
// Project the polygons onto the axis.
|
|
93
93
|
flattenPointsOn(aPoints, axis, rangeA);
|
|
@@ -161,15 +161,15 @@ function isSeparatingAxis(aPos, bPos, aPoints, bPoints, axis, response) {
|
|
|
161
161
|
* </pre>
|
|
162
162
|
*
|
|
163
163
|
* @ignore
|
|
164
|
-
* @param {
|
|
165
|
-
* @param {
|
|
164
|
+
* @param {Vector2d} line The line segment.
|
|
165
|
+
* @param {Vector2d} point The point.
|
|
166
166
|
* @returns {number} LEFT_VORNOI_REGION (-1) if it is the left region,
|
|
167
167
|
* MIDDLE_VORNOI_REGION (0) if it is the middle region,
|
|
168
168
|
* RIGHT_VORNOI_REGION (1) if it is the right region.
|
|
169
169
|
*/
|
|
170
170
|
function vornoiRegion(line, point) {
|
|
171
171
|
var len2 = line.length2();
|
|
172
|
-
var dp = point.
|
|
172
|
+
var dp = point.dot(line);
|
|
173
173
|
if (dp < 0) {
|
|
174
174
|
// If the point is beyond the start of the line, it is in the
|
|
175
175
|
// left vornoi region.
|
|
@@ -187,10 +187,10 @@ function vornoiRegion(line, point) {
|
|
|
187
187
|
/**
|
|
188
188
|
* Checks whether polygons collide.
|
|
189
189
|
* @ignore
|
|
190
|
-
* @param {
|
|
191
|
-
* @param {
|
|
192
|
-
* @param {
|
|
193
|
-
* @param {
|
|
190
|
+
* @param {Renderable} a a reference to the object A.
|
|
191
|
+
* @param {Polygon} polyA a reference to the object A Polygon to be tested
|
|
192
|
+
* @param {Renderable} b a reference to the object B.
|
|
193
|
+
* @param {Polygon} polyB a reference to the object B Polygon to be tested
|
|
194
194
|
* @param {Response=} response Response object (optional) that will be populated if they intersect.
|
|
195
195
|
* @returns {boolean} true if they intersect, false if they don't.
|
|
196
196
|
*/
|
|
@@ -241,10 +241,10 @@ export function testPolygonPolygon(a, polyA, b, polyB, response) {
|
|
|
241
241
|
/**
|
|
242
242
|
* Check if two Ellipse collide.
|
|
243
243
|
* @ignore
|
|
244
|
-
* @param {
|
|
245
|
-
* @param {
|
|
246
|
-
* @param {
|
|
247
|
-
* @param {
|
|
244
|
+
* @param {Renderable} a a reference to the object A.
|
|
245
|
+
* @param {Ellipse} ellipseA a reference to the object A Ellipse to be tested
|
|
246
|
+
* @param {Renderable} b a reference to the object B.
|
|
247
|
+
* @param {Ellipse} ellipseB a reference to the object B Ellipse to be tested
|
|
248
248
|
* @param {Response=} response Response object (optional) that will be populated if
|
|
249
249
|
* the circles intersect.
|
|
250
250
|
* @returns {boolean} true if the circles intersect, false if they don't.
|
|
@@ -282,10 +282,10 @@ export function testEllipseEllipse(a, ellipseA, b, ellipseB, response) {
|
|
|
282
282
|
/**
|
|
283
283
|
* Check if a polygon and an ellipse collide.
|
|
284
284
|
* @ignore
|
|
285
|
-
* @param {
|
|
286
|
-
* @param {
|
|
287
|
-
* @param {
|
|
288
|
-
* @param {
|
|
285
|
+
* @param {Renderable} a a reference to the object A.
|
|
286
|
+
* @param {Polygon} polyA a reference to the object A Polygon to be tested
|
|
287
|
+
* @param {Renderable} b a reference to the object B.
|
|
288
|
+
* @param {Ellipse} ellipseB a reference to the object B Ellipse to be tested
|
|
289
289
|
* @param {Response=} response Response object (optional) that will be populated if they intersect.
|
|
290
290
|
* @returns {boolean} true if they intersect, false if they don't.
|
|
291
291
|
*/
|
|
@@ -400,7 +400,7 @@ export function testPolygonEllipse(a, polyA, b, ellipseB, response) {
|
|
|
400
400
|
normal.copy(polyA.normals[i]);
|
|
401
401
|
// Find the perpendicular distance between the center of the
|
|
402
402
|
// circle and the edge.
|
|
403
|
-
dist = point.
|
|
403
|
+
dist = point.dot(normal);
|
|
404
404
|
var distAbs = Math.abs(dist);
|
|
405
405
|
// If the circle is on the outside of the edge, there is no intersection.
|
|
406
406
|
if ((len === 1 || dist > 0) && distAbs > radius) {
|
|
@@ -448,10 +448,10 @@ export function testPolygonEllipse(a, polyA, b, ellipseB, response) {
|
|
|
448
448
|
* **NOTE:** This is slightly less efficient than testPolygonEllipse as it just
|
|
449
449
|
* runs testPolygonEllipse and reverses the response at the end.
|
|
450
450
|
* @ignore
|
|
451
|
-
* @param {
|
|
452
|
-
* @param {
|
|
453
|
-
* @param {
|
|
454
|
-
* @param {
|
|
451
|
+
* @param {Renderable} a a reference to the object A.
|
|
452
|
+
* @param {Ellipse} ellipseA a reference to the object A Ellipse to be tested
|
|
453
|
+
* @param {Renderable} b a reference to the object B.
|
|
454
|
+
* @param {Polygon} polyB a reference to the object B Polygon to be tested
|
|
455
455
|
* @param {Response=} response Response object (optional) that will be populated if
|
|
456
456
|
* they intersect.
|
|
457
457
|
* @returns {boolean} true if they intersect, false if they don't.
|
package/src/physics/world.js
CHANGED
|
@@ -9,21 +9,16 @@ import state from "./../state/state.js";
|
|
|
9
9
|
/**
|
|
10
10
|
* @classdesc
|
|
11
11
|
* an object representing the physic world, and responsible for managing and updating all childs and physics
|
|
12
|
-
* @
|
|
13
|
-
* @extends me.Container
|
|
14
|
-
* @memberOf me
|
|
15
|
-
* @constructor
|
|
16
|
-
* @param {number} [x=0] position of the container (accessible via the inherited pos.x property)
|
|
17
|
-
* @param {number} [y=0] position of the container (accessible via the inherited pos.y property)
|
|
18
|
-
* @param {number} [w=me.game.viewport.width] width of the container
|
|
19
|
-
* @param {number} [h=me.game.viewport.height] height of the container
|
|
12
|
+
* @augments Container
|
|
20
13
|
*/
|
|
21
14
|
class World extends Container {
|
|
22
15
|
/**
|
|
23
|
-
* @
|
|
16
|
+
* @param {number} [x=0] position of the container (accessible via the inherited pos.x property)
|
|
17
|
+
* @param {number} [y=0] position of the container (accessible via the inherited pos.y property)
|
|
18
|
+
* @param {number} [width=game.viewport.width] width of the container
|
|
19
|
+
* @param {number} [height=game.viewport.height] height of the container
|
|
24
20
|
*/
|
|
25
21
|
constructor(x = 0, y = 0, width = Infinity, height = Infinity) {
|
|
26
|
-
|
|
27
22
|
// call the super constructor
|
|
28
23
|
super(x, y, width, height, true);
|
|
29
24
|
|
|
@@ -37,21 +32,21 @@ class World extends Container {
|
|
|
37
32
|
* the rate at which the game world is updated,
|
|
38
33
|
* may be greater than or lower than the display fps
|
|
39
34
|
* @public
|
|
40
|
-
* @type {
|
|
35
|
+
* @type {Vector2d}
|
|
41
36
|
* @default 60
|
|
42
37
|
* @name fps
|
|
43
|
-
* @
|
|
44
|
-
* @see
|
|
38
|
+
* @memberof World
|
|
39
|
+
* @see timer.maxfps
|
|
45
40
|
*/
|
|
46
41
|
this.fps = 60;
|
|
47
42
|
|
|
48
43
|
/**
|
|
49
44
|
* world gravity
|
|
50
45
|
* @public
|
|
51
|
-
* @type {
|
|
46
|
+
* @type {Vector2d}
|
|
52
47
|
* @default <0,0.98>
|
|
53
48
|
* @name gravity
|
|
54
|
-
* @
|
|
49
|
+
* @memberof World
|
|
55
50
|
*/
|
|
56
51
|
this.gravity = new Vector2d(0, 0.98);
|
|
57
52
|
|
|
@@ -65,14 +60,14 @@ class World extends Container {
|
|
|
65
60
|
* property to your layer (in Tiled).
|
|
66
61
|
* @type {boolean}
|
|
67
62
|
* @default false
|
|
68
|
-
* @
|
|
63
|
+
* @memberof World
|
|
69
64
|
*/
|
|
70
65
|
this.preRender = false;
|
|
71
66
|
|
|
72
67
|
/**
|
|
73
68
|
* the active physic bodies in this simulation
|
|
74
69
|
* @name bodies
|
|
75
|
-
* @
|
|
70
|
+
* @memberof World
|
|
76
71
|
* @public
|
|
77
72
|
* @type {Set}
|
|
78
73
|
*/
|
|
@@ -81,9 +76,9 @@ class World extends Container {
|
|
|
81
76
|
/**
|
|
82
77
|
* the instance of the game world quadtree used for broadphase
|
|
83
78
|
* @name broadphase
|
|
84
|
-
* @
|
|
79
|
+
* @memberof World
|
|
85
80
|
* @public
|
|
86
|
-
* @type {
|
|
81
|
+
* @type {QuadTree}
|
|
87
82
|
*/
|
|
88
83
|
this.broadphase = new QuadTree(this.getBounds().clone(), collision.maxChildren, collision.maxDepth);
|
|
89
84
|
|
|
@@ -100,7 +95,7 @@ class World extends Container {
|
|
|
100
95
|
/**
|
|
101
96
|
* reset the game world
|
|
102
97
|
* @name reset
|
|
103
|
-
* @
|
|
98
|
+
* @memberof World
|
|
104
99
|
* @function
|
|
105
100
|
*/
|
|
106
101
|
reset() {
|
|
@@ -121,11 +116,11 @@ class World extends Container {
|
|
|
121
116
|
/**
|
|
122
117
|
* Add a physic body to the game world
|
|
123
118
|
* @name addBody
|
|
124
|
-
* @
|
|
125
|
-
* @see
|
|
119
|
+
* @memberof World
|
|
120
|
+
* @see Container.addChild
|
|
126
121
|
* @function
|
|
127
|
-
* @param {
|
|
128
|
-
* @returns {
|
|
122
|
+
* @param {Body} body
|
|
123
|
+
* @returns {World} this game world
|
|
129
124
|
*/
|
|
130
125
|
addBody(body) {
|
|
131
126
|
//add it to the list of active body
|
|
@@ -136,11 +131,11 @@ class World extends Container {
|
|
|
136
131
|
/**
|
|
137
132
|
* Remove a physic body from the game world
|
|
138
133
|
* @name removeBody
|
|
139
|
-
* @
|
|
140
|
-
* @see
|
|
134
|
+
* @memberof World
|
|
135
|
+
* @see Container.removeChild
|
|
141
136
|
* @function
|
|
142
|
-
* @param {
|
|
143
|
-
* @returns {
|
|
137
|
+
* @param {Body} body
|
|
138
|
+
* @returns {World} this game world
|
|
144
139
|
*/
|
|
145
140
|
removeBody(body) {
|
|
146
141
|
//remove from the list of active body
|
|
@@ -151,7 +146,7 @@ class World extends Container {
|
|
|
151
146
|
/**
|
|
152
147
|
* update the game world
|
|
153
148
|
* @name reset
|
|
154
|
-
* @
|
|
149
|
+
* @memberof World
|
|
155
150
|
* @function
|
|
156
151
|
* @param {number} dt the time passed since the last frame update
|
|
157
152
|
* @returns {boolean} true if the word is dirty
|
package/src/plugin/plugin.js
CHANGED
|
@@ -3,9 +3,8 @@ import { version } from "./../index.js";
|
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* This namespace is a container for all registered plugins.
|
|
6
|
-
* @see
|
|
7
|
-
* @namespace
|
|
8
|
-
* @memberOf me
|
|
6
|
+
* @see plugin.register
|
|
7
|
+
* @namespace plugins
|
|
9
8
|
*/
|
|
10
9
|
export var plugins = {};
|
|
11
10
|
|
|
@@ -19,7 +18,7 @@ class BasePlugin {
|
|
|
19
18
|
* @public
|
|
20
19
|
* @type {string}
|
|
21
20
|
* @default "__VERSION__"
|
|
22
|
-
* @name
|
|
21
|
+
* @name plugin.Base#version
|
|
23
22
|
*/
|
|
24
23
|
this.version = "__VERSION__";
|
|
25
24
|
}
|
|
@@ -27,26 +26,23 @@ class BasePlugin {
|
|
|
27
26
|
|
|
28
27
|
/**
|
|
29
28
|
* @namespace plugin
|
|
30
|
-
* @memberOf me
|
|
31
29
|
*/
|
|
32
30
|
export var plugin = {
|
|
33
31
|
|
|
34
32
|
/**
|
|
35
33
|
* a base Object for plugin <br>
|
|
36
34
|
* plugin must be installed using the register function
|
|
37
|
-
* @see
|
|
35
|
+
* @see plugin
|
|
38
36
|
* @class
|
|
39
|
-
* @
|
|
40
|
-
* @
|
|
41
|
-
* @memberOf me
|
|
42
|
-
* @constructor
|
|
37
|
+
* @name Base
|
|
38
|
+
* @memberof plugin
|
|
43
39
|
*/
|
|
44
40
|
Base : BasePlugin,
|
|
45
41
|
|
|
46
42
|
/**
|
|
47
43
|
* patch a melonJS function
|
|
48
44
|
* @name patch
|
|
49
|
-
* @
|
|
45
|
+
* @memberof plugin
|
|
50
46
|
* @public
|
|
51
47
|
* @function
|
|
52
48
|
* @param {object} proto target object
|
|
@@ -66,7 +62,7 @@ export var plugin = {
|
|
|
66
62
|
if (typeof proto.prototype !== "undefined") {
|
|
67
63
|
proto = proto.prototype;
|
|
68
64
|
}
|
|
69
|
-
// reuse the logic behind
|
|
65
|
+
// reuse the logic behind object extends
|
|
70
66
|
if (typeof(proto[name]) === "function") {
|
|
71
67
|
// save the original function
|
|
72
68
|
var _parent = proto[name];
|
|
@@ -91,11 +87,11 @@ export var plugin = {
|
|
|
91
87
|
/**
|
|
92
88
|
* Register a plugin.
|
|
93
89
|
* @name register
|
|
94
|
-
* @
|
|
95
|
-
* @see
|
|
90
|
+
* @memberof plugin
|
|
91
|
+
* @see Base
|
|
96
92
|
* @public
|
|
97
93
|
* @function
|
|
98
|
-
* @param {
|
|
94
|
+
* @param {plugin.Base} pluginObj Plugin object to instantiate and register
|
|
99
95
|
* @param {string} name
|
|
100
96
|
* @param {object} [...arguments] all extra parameters will be passed to the plugin constructor
|
|
101
97
|
* @example
|
package/src/renderable/GUI.js
CHANGED
|
@@ -9,44 +9,38 @@ import { registerPointerEvent, releasePointerEvent} from "./../input/input.js";
|
|
|
9
9
|
* A very basic object to manage GUI elements <br>
|
|
10
10
|
* The object simply register on the "pointerdown" <br>
|
|
11
11
|
* or "touchstart" event and call the onClick function"
|
|
12
|
-
* @
|
|
13
|
-
* @extends me.Sprite
|
|
14
|
-
* @memberOf me
|
|
15
|
-
* @constructor
|
|
16
|
-
* @param {number} x the x coordinate of the GUI Object
|
|
17
|
-
* @param {number} y the y coordinate of the GUI Object
|
|
18
|
-
* @param {object} settings See {@link me.Sprite}
|
|
19
|
-
* @example
|
|
20
|
-
* // create a basic GUI Object
|
|
21
|
-
* class myButton extends GUI_Object {
|
|
22
|
-
* constructor(x, y) {
|
|
23
|
-
* var settings = {}
|
|
24
|
-
* settings.image = "button";
|
|
25
|
-
* settings.framewidth = 100;
|
|
26
|
-
* settings.frameheight = 50;
|
|
27
|
-
* // super constructor
|
|
28
|
-
* super(x, y, settings);
|
|
29
|
-
* // define the object z order
|
|
30
|
-
* this.pos.z = 4;
|
|
31
|
-
* }
|
|
32
|
-
*
|
|
33
|
-
* // output something in the console
|
|
34
|
-
* // when the object is clicked
|
|
35
|
-
* onClick:function (event) {
|
|
36
|
-
* console.log("clicked!");
|
|
37
|
-
* // don't propagate the event
|
|
38
|
-
* return false;
|
|
39
|
-
* }
|
|
40
|
-
* });
|
|
41
|
-
*
|
|
42
|
-
* // add the object at pos (10,10)
|
|
43
|
-
* me.game.world.addChild(new myButton(10,10));
|
|
12
|
+
* @augments Sprite
|
|
44
13
|
*/
|
|
45
|
-
|
|
46
14
|
class GUI_Object extends Sprite {
|
|
47
|
-
|
|
48
15
|
/**
|
|
49
|
-
* @
|
|
16
|
+
* @param {number} x the x coordinate of the GUI Object
|
|
17
|
+
* @param {number} y the y coordinate of the GUI Object
|
|
18
|
+
* @param {object} settings See {@link Sprite}
|
|
19
|
+
* @example
|
|
20
|
+
* // create a basic GUI Object
|
|
21
|
+
* class myButton extends GUI_Object {
|
|
22
|
+
* constructor(x, y) {
|
|
23
|
+
* var settings = {}
|
|
24
|
+
* settings.image = "button";
|
|
25
|
+
* settings.framewidth = 100;
|
|
26
|
+
* settings.frameheight = 50;
|
|
27
|
+
* // super constructor
|
|
28
|
+
* super(x, y, settings);
|
|
29
|
+
* // define the object z order
|
|
30
|
+
* this.pos.z = 4;
|
|
31
|
+
* }
|
|
32
|
+
*
|
|
33
|
+
* // output something in the console
|
|
34
|
+
* // when the object is clicked
|
|
35
|
+
* onClick:function (event) {
|
|
36
|
+
* console.log("clicked!");
|
|
37
|
+
* // don't propagate the event
|
|
38
|
+
* return false;
|
|
39
|
+
* }
|
|
40
|
+
* });
|
|
41
|
+
*
|
|
42
|
+
* // add the object at pos (10,10)
|
|
43
|
+
* me.game.world.addChild(new myButton(10,10));
|
|
50
44
|
*/
|
|
51
45
|
constructor(x, y, settings) {
|
|
52
46
|
|
|
@@ -58,7 +52,7 @@ class GUI_Object extends Sprite {
|
|
|
58
52
|
* @public
|
|
59
53
|
* @type {boolean}
|
|
60
54
|
* @default true
|
|
61
|
-
* @name
|
|
55
|
+
* @name GUI_Object#isClickable
|
|
62
56
|
*/
|
|
63
57
|
this.isClickable = true;
|
|
64
58
|
|
|
@@ -66,7 +60,7 @@ class GUI_Object extends Sprite {
|
|
|
66
60
|
* Tap and hold threshold timeout in ms
|
|
67
61
|
* @type {number}
|
|
68
62
|
* @default 250
|
|
69
|
-
* @name
|
|
63
|
+
* @name GUI_Object#holdThreshold
|
|
70
64
|
*/
|
|
71
65
|
this.holdThreshold = 250;
|
|
72
66
|
|
|
@@ -75,7 +69,7 @@ class GUI_Object extends Sprite {
|
|
|
75
69
|
* @public
|
|
76
70
|
* @type {boolean}
|
|
77
71
|
* @default false
|
|
78
|
-
* @name
|
|
72
|
+
* @name GUI_Object#isHoldable
|
|
79
73
|
*/
|
|
80
74
|
this.isHoldable = false;
|
|
81
75
|
|
|
@@ -84,7 +78,7 @@ class GUI_Object extends Sprite {
|
|
|
84
78
|
* @public
|
|
85
79
|
* @type {boolean}
|
|
86
80
|
* @default false
|
|
87
|
-
* @name
|
|
81
|
+
* @name GUI_Object#hover
|
|
88
82
|
*/
|
|
89
83
|
this.hover = false;
|
|
90
84
|
|
|
@@ -122,10 +116,10 @@ class GUI_Object extends Sprite {
|
|
|
122
116
|
/**
|
|
123
117
|
* function called when the object is pressed (to be extended)
|
|
124
118
|
* @name onClick
|
|
125
|
-
* @
|
|
119
|
+
* @memberof GUI_Object.prototype
|
|
126
120
|
* @public
|
|
127
121
|
* @function
|
|
128
|
-
* @param {
|
|
122
|
+
* @param {Pointer} event the event object
|
|
129
123
|
* @returns {boolean} return false if we need to stop propagating the event
|
|
130
124
|
*/
|
|
131
125
|
onClick(/* event */) {
|
|
@@ -145,10 +139,10 @@ class GUI_Object extends Sprite {
|
|
|
145
139
|
/**
|
|
146
140
|
* function called when the pointer is over the object
|
|
147
141
|
* @name onOver
|
|
148
|
-
* @
|
|
142
|
+
* @memberof GUI_Object.prototype
|
|
149
143
|
* @public
|
|
150
144
|
* @function
|
|
151
|
-
* @param {
|
|
145
|
+
* @param {Pointer} event the event object
|
|
152
146
|
*/
|
|
153
147
|
onOver(/* event */) {}
|
|
154
148
|
|
|
@@ -166,10 +160,10 @@ class GUI_Object extends Sprite {
|
|
|
166
160
|
/**
|
|
167
161
|
* function called when the pointer is leaving the object area
|
|
168
162
|
* @name onOut
|
|
169
|
-
* @
|
|
163
|
+
* @memberof GUI_Object.prototype
|
|
170
164
|
* @public
|
|
171
165
|
* @function
|
|
172
|
-
* @param {
|
|
166
|
+
* @param {Pointer} event the event object
|
|
173
167
|
*/
|
|
174
168
|
onOut(/* event */) {
|
|
175
169
|
|
|
@@ -191,7 +185,7 @@ class GUI_Object extends Sprite {
|
|
|
191
185
|
/**
|
|
192
186
|
* function called when the object is pressed and released (to be extended)
|
|
193
187
|
* @name onRelease
|
|
194
|
-
* @
|
|
188
|
+
* @memberof GUI_Object.prototype
|
|
195
189
|
* @public
|
|
196
190
|
* @function
|
|
197
191
|
* @returns {boolean} return false if we need to stop propagating the event
|
|
@@ -216,7 +210,7 @@ class GUI_Object extends Sprite {
|
|
|
216
210
|
* function called when the object is pressed and held<br>
|
|
217
211
|
* to be extended <br>
|
|
218
212
|
* @name onHold
|
|
219
|
-
* @
|
|
213
|
+
* @memberof GUI_Object.prototype
|
|
220
214
|
* @public
|
|
221
215
|
* @function
|
|
222
216
|
*/
|
|
@@ -1,23 +1,18 @@
|
|
|
1
1
|
import Sprite from "./sprite.js";
|
|
2
2
|
import Body from "./../physics/body.js";
|
|
3
|
-
import Rect from "./../
|
|
3
|
+
import Rect from "./../geometries/rectangle.js";
|
|
4
4
|
import collision from "./../physics/collision.js";
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* @classdesc
|
|
8
8
|
* a basic collectable helper class for immovable object (e.g. a coin)
|
|
9
|
-
* @
|
|
10
|
-
* @extends me.Sprite
|
|
11
|
-
* @memberOf me
|
|
12
|
-
* @constructor
|
|
13
|
-
* @param {number} x the x coordinates of the collectable
|
|
14
|
-
* @param {number} y the y coordinates of the collectable
|
|
15
|
-
* @param {object} settings See {@link me.Sprite}
|
|
9
|
+
* @augments Sprite
|
|
16
10
|
*/
|
|
17
|
-
|
|
18
11
|
class Collectable extends Sprite {
|
|
19
12
|
/**
|
|
20
|
-
* @
|
|
13
|
+
* @param {number} x the x coordinates of the collectable
|
|
14
|
+
* @param {number} y the y coordinates of the collectable
|
|
15
|
+
* @param {object} settings See {@link Sprite}
|
|
21
16
|
*/
|
|
22
17
|
constructor(x, y, settings) {
|
|
23
18
|
|
|
@@ -6,18 +6,13 @@ import Renderable from "./renderable.js";
|
|
|
6
6
|
/**
|
|
7
7
|
* @classdesc
|
|
8
8
|
* a generic Color Layer Object. Fills the entire Canvas with the color not just the container the object belongs to.
|
|
9
|
-
* @
|
|
10
|
-
* @extends me.Renderable
|
|
11
|
-
* @memberOf me
|
|
12
|
-
* @constructor
|
|
13
|
-
* @param {string} name Layer name
|
|
14
|
-
* @param {me.Color|string} color CSS color
|
|
15
|
-
* @param {number} [z = 0] z-index position
|
|
9
|
+
* @augments Renderable
|
|
16
10
|
*/
|
|
17
11
|
class ColorLayer extends Renderable {
|
|
18
|
-
|
|
19
12
|
/**
|
|
20
|
-
* @
|
|
13
|
+
* @param {string} name Layer name
|
|
14
|
+
* @param {Color|string} color CSS color
|
|
15
|
+
* @param {number} [z = 0] z-index position
|
|
21
16
|
*/
|
|
22
17
|
constructor(name, color, z) {
|
|
23
18
|
// parent constructor
|
|
@@ -26,9 +21,9 @@ class ColorLayer extends Renderable {
|
|
|
26
21
|
/**
|
|
27
22
|
* the layer color component
|
|
28
23
|
* @public
|
|
29
|
-
* @type {
|
|
24
|
+
* @type {Color}
|
|
30
25
|
* @name color
|
|
31
|
-
* @
|
|
26
|
+
* @memberof ColorLayer#
|
|
32
27
|
*/
|
|
33
28
|
this.color = pool.pull("Color").parseCSS(color);
|
|
34
29
|
|
|
@@ -50,14 +45,14 @@ class ColorLayer extends Renderable {
|
|
|
50
45
|
* @ignore
|
|
51
46
|
*/
|
|
52
47
|
draw(renderer, rect) {
|
|
53
|
-
var color = renderer.getColor();
|
|
54
48
|
var vpos = viewport.pos;
|
|
55
|
-
renderer.
|
|
56
|
-
renderer.
|
|
49
|
+
renderer.save();
|
|
50
|
+
renderer.clipRect(
|
|
57
51
|
rect.left - vpos.x, rect.top - vpos.y,
|
|
58
52
|
rect.width, rect.height
|
|
59
53
|
);
|
|
60
|
-
renderer.
|
|
54
|
+
renderer.clearColor(this.color);
|
|
55
|
+
renderer.restore();
|
|
61
56
|
}
|
|
62
57
|
|
|
63
58
|
/**
|