melonjs 14.4.0 → 15.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 +13 -57
- package/dist/melonjs.mjs/_virtual/_commonjsHelpers.js +1 -1
- package/dist/melonjs.mjs/_virtual/arraymultimap.js +1 -1
- package/dist/melonjs.mjs/_virtual/earcut.js +1 -1
- package/dist/melonjs.mjs/_virtual/howler.js +1 -1
- package/dist/melonjs.mjs/_virtual/index.js +1 -1
- package/dist/melonjs.mjs/_virtual/index2.js +1 -1
- package/dist/melonjs.mjs/_virtual/multimap.js +1 -1
- package/dist/melonjs.mjs/_virtual/setmultimap.js +1 -1
- package/dist/melonjs.mjs/application/application.js +1 -1
- package/dist/melonjs.mjs/application/header.js +1 -1
- package/dist/melonjs.mjs/application/resize.js +1 -1
- package/dist/melonjs.mjs/application/settings.js +1 -1
- package/dist/melonjs.mjs/audio/audio.js +5 -7
- package/dist/melonjs.mjs/camera/camera2d.js +1 -1
- package/dist/melonjs.mjs/const.js +1 -1
- package/dist/melonjs.mjs/entity/entity.js +43 -9
- package/dist/melonjs.mjs/geometries/ellipse.js +2 -3
- package/dist/melonjs.mjs/geometries/line.js +1 -1
- package/dist/melonjs.mjs/geometries/path2d.js +20 -44
- package/dist/melonjs.mjs/geometries/point.js +1 -6
- package/dist/melonjs.mjs/geometries/poly.js +2 -5
- package/dist/melonjs.mjs/geometries/rectangle.js +13 -9
- package/dist/melonjs.mjs/geometries/roundrect.js +1 -1
- package/dist/melonjs.mjs/index.js +10 -6
- package/dist/melonjs.mjs/input/gamepad.js +10 -16
- package/dist/melonjs.mjs/input/input.js +1 -1
- package/dist/melonjs.mjs/input/keyboard.js +1 -1
- package/dist/melonjs.mjs/input/pointer.js +1 -1
- package/dist/melonjs.mjs/input/pointerevent.js +3 -17
- package/dist/melonjs.mjs/lang/console.js +1 -1
- package/dist/melonjs.mjs/lang/deprecated.js +1 -1
- package/dist/melonjs.mjs/level/level.js +3 -3
- package/dist/melonjs.mjs/level/tiled/TMXGroup.js +1 -1
- package/dist/melonjs.mjs/level/tiled/TMXLayer.js +1 -8
- package/dist/melonjs.mjs/level/tiled/TMXObject.js +1 -1
- package/dist/melonjs.mjs/level/tiled/TMXTile.js +1 -1
- package/dist/melonjs.mjs/level/tiled/TMXTileMap.js +8 -4
- package/dist/melonjs.mjs/level/tiled/TMXTileset.js +5 -5
- package/dist/melonjs.mjs/level/tiled/TMXTilesetGroup.js +1 -1
- package/dist/melonjs.mjs/level/tiled/TMXUtils.js +1 -1
- package/dist/melonjs.mjs/level/tiled/constants.js +1 -1
- package/dist/melonjs.mjs/level/tiled/renderer/TMXHexagonalRenderer.js +1 -1
- package/dist/melonjs.mjs/level/tiled/renderer/TMXIsometricRenderer.js +1 -1
- package/dist/melonjs.mjs/level/tiled/renderer/TMXOrthogonalRenderer.js +1 -1
- package/dist/melonjs.mjs/level/tiled/renderer/TMXRenderer.js +1 -1
- package/dist/melonjs.mjs/level/tiled/renderer/TMXStaggeredRenderer.js +1 -1
- package/dist/melonjs.mjs/level/tiled/renderer/autodetect.js +1 -1
- package/dist/melonjs.mjs/loader/cache.js +24 -0
- package/dist/melonjs.mjs/loader/loader.js +331 -716
- package/dist/melonjs.mjs/loader/loadingscreen.js +4 -4
- package/dist/melonjs.mjs/loader/melonjs_logo.png.js +1 -1
- package/dist/melonjs.mjs/loader/parser.js +281 -0
- package/dist/melonjs.mjs/loader/settings.js +91 -0
- package/dist/melonjs.mjs/math/color.js +9 -8
- package/dist/melonjs.mjs/math/math.js +1 -1
- package/dist/melonjs.mjs/math/matrix2.js +7 -9
- package/dist/melonjs.mjs/math/matrix3.js +18 -21
- package/dist/melonjs.mjs/math/observable_vector2.js +3 -3
- package/dist/melonjs.mjs/math/observable_vector3.js +3 -4
- package/dist/melonjs.mjs/math/vector2.js +3 -3
- package/dist/melonjs.mjs/math/vector3.js +3 -4
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/arraymultimap.js +1 -1
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/index.js +1 -1
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/multimap.js +1 -1
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/setmultimap.js +1 -1
- package/dist/melonjs.mjs/node_modules/earcut/src/earcut.js +1 -1
- package/dist/melonjs.mjs/node_modules/eventemitter3/index.js +1 -1
- package/dist/melonjs.mjs/node_modules/eventemitter3/index2.js +1 -1
- package/dist/melonjs.mjs/node_modules/howler/dist/howler.js +1 -1
- package/dist/melonjs.mjs/particles/emitter.js +3 -3
- package/dist/melonjs.mjs/particles/particle.js +1 -1
- package/dist/melonjs.mjs/particles/settings.js +1 -1
- package/dist/melonjs.mjs/physics/body.js +18 -14
- package/dist/melonjs.mjs/physics/bounds.js +18 -70
- package/dist/melonjs.mjs/physics/collision.js +1 -1
- package/dist/melonjs.mjs/physics/detector.js +1 -1
- package/dist/melonjs.mjs/physics/quadtree.js +1 -1
- package/dist/melonjs.mjs/physics/response.js +1 -1
- package/dist/melonjs.mjs/physics/sat.js +1 -1
- package/dist/melonjs.mjs/physics/world.js +1 -1
- package/dist/melonjs.mjs/plugin/plugin.js +3 -3
- package/dist/melonjs.mjs/renderable/collectable.js +1 -1
- package/dist/melonjs.mjs/renderable/colorlayer.js +1 -1
- package/dist/melonjs.mjs/renderable/container.js +25 -19
- package/dist/melonjs.mjs/renderable/dragndrop.js +1 -1
- package/dist/melonjs.mjs/renderable/imagelayer.js +7 -1
- package/dist/melonjs.mjs/renderable/light2d.js +1 -1
- package/dist/melonjs.mjs/renderable/nineslicesprite.js +1 -1
- package/dist/melonjs.mjs/renderable/renderable.js +148 -105
- package/dist/melonjs.mjs/renderable/sprite.js +33 -54
- package/dist/melonjs.mjs/renderable/trigger.js +1 -1
- package/dist/melonjs.mjs/renderable/ui/uibaseelement.js +1 -1
- package/dist/melonjs.mjs/renderable/ui/uispriteelement.js +1 -1
- package/dist/melonjs.mjs/renderable/ui/uitextbutton.js +1 -3
- package/dist/melonjs.mjs/state/stage.js +1 -1
- package/dist/melonjs.mjs/state/state.js +2 -2
- package/dist/melonjs.mjs/system/device.js +2 -2
- package/dist/melonjs.mjs/system/dom.js +1 -1
- package/dist/melonjs.mjs/system/event.js +1 -1
- package/dist/melonjs.mjs/system/platform.js +1 -1
- package/dist/melonjs.mjs/system/pooling.js +8 -18
- package/dist/melonjs.mjs/system/save.js +1 -1
- package/dist/melonjs.mjs/system/timer.js +1 -1
- package/dist/melonjs.mjs/text/bitmaptext.js +66 -8
- package/dist/melonjs.mjs/text/bitmaptextdata.js +1 -1
- package/dist/melonjs.mjs/text/glyph.js +1 -1
- package/dist/melonjs.mjs/text/text.js +56 -86
- package/dist/melonjs.mjs/text/textmetrics.js +1 -1
- package/dist/melonjs.mjs/text/textstyle.js +4 -6
- package/dist/melonjs.mjs/tweens/easing.js +1 -1
- package/dist/melonjs.mjs/tweens/interpolation.js +1 -1
- package/dist/melonjs.mjs/tweens/tween.js +1 -1
- package/dist/melonjs.mjs/utils/agent.js +1 -1
- package/dist/melonjs.mjs/utils/array.js +1 -1
- package/dist/melonjs.mjs/utils/file.js +1 -1
- package/dist/melonjs.mjs/utils/function.js +1 -1
- package/dist/melonjs.mjs/utils/string.js +2 -2
- package/dist/melonjs.mjs/utils/utils.js +2 -4
- package/dist/melonjs.mjs/video/canvas/canvas_renderer.js +7 -11
- package/dist/melonjs.mjs/video/renderer.js +2 -13
- package/dist/melonjs.mjs/video/texture/atlas.js +12 -17
- package/dist/melonjs.mjs/video/texture/cache.js +3 -3
- package/dist/melonjs.mjs/video/texture/canvas_texture.js +1 -1
- package/dist/melonjs.mjs/video/utils/autodetect.js +1 -1
- package/dist/melonjs.mjs/video/video.js +2 -2
- package/dist/melonjs.mjs/video/webgl/buffer/vertex.js +21 -17
- package/dist/melonjs.mjs/video/webgl/compositors/compositor.js +235 -0
- package/dist/melonjs.mjs/video/webgl/compositors/primitive_compositor.js +77 -0
- package/dist/melonjs.mjs/video/webgl/compositors/quad_compositor.js +249 -0
- package/dist/melonjs.mjs/video/webgl/{webgl_compositor.js → compositors/webgl_compositor.js} +20 -205
- package/dist/melonjs.mjs/video/webgl/glshader.js +1 -1
- package/dist/melonjs.mjs/video/webgl/shaders/primitive.frag.js +1 -1
- package/dist/melonjs.mjs/video/webgl/shaders/primitive.vert.js +2 -2
- package/dist/melonjs.mjs/video/webgl/shaders/quad.frag.js +1 -1
- package/dist/melonjs.mjs/video/webgl/shaders/quad.vert.js +2 -2
- package/dist/melonjs.mjs/video/webgl/utils/attributes.js +1 -1
- package/dist/melonjs.mjs/video/webgl/utils/precision.js +1 -1
- package/dist/melonjs.mjs/video/webgl/utils/program.js +1 -1
- package/dist/melonjs.mjs/video/webgl/utils/string.js +1 -1
- package/dist/melonjs.mjs/video/webgl/utils/uniforms.js +1 -1
- package/dist/melonjs.mjs/video/webgl/webgl_renderer.js +139 -149
- package/dist/melonjs.module.js +26320 -26376
- package/dist/types/entity/entity.d.ts +3 -3
- package/dist/types/geometries/path2d.d.ts +5 -31
- package/dist/types/geometries/point.d.ts +2 -7
- package/dist/types/geometries/poly.d.ts +0 -1
- package/dist/types/index.d.ts +5 -3
- package/dist/types/loader/cache.d.ts +7 -0
- package/dist/types/loader/loader.d.ts +166 -181
- package/dist/types/loader/parser.d.ts +41 -0
- package/dist/types/loader/settings.d.ts +57 -0
- package/dist/types/particles/emitter.d.ts +4 -4
- package/dist/types/physics/bounds.d.ts +29 -84
- package/dist/types/renderable/container.d.ts +0 -11
- package/dist/types/renderable/renderable.d.ts +43 -31
- package/dist/types/renderable/sprite.d.ts +3 -3
- package/dist/types/renderable/ui/uitextbutton.d.ts +0 -1
- package/dist/types/state/state.d.ts +1 -1
- package/dist/types/system/pooling.d.ts +2 -2
- package/dist/types/text/text.d.ts +6 -20
- package/dist/types/text/textstyle.d.ts +1 -1
- package/dist/types/video/canvas/canvas_renderer.d.ts +0 -5
- package/dist/types/video/renderer.d.ts +1 -5
- package/dist/types/video/webgl/buffer/vertex.d.ts +3 -3
- package/dist/types/video/webgl/compositors/compositor.d.ts +107 -0
- package/dist/types/video/webgl/compositors/primitive_compositor.d.ts +22 -0
- package/dist/types/video/webgl/compositors/quad_compositor.d.ts +72 -0
- package/dist/types/video/webgl/compositors/webgl_compositor.d.ts +86 -0
- package/dist/types/video/webgl/webgl_compositor.d.ts +2 -3
- package/dist/types/video/webgl/webgl_renderer.d.ts +34 -28
- package/package.json +18 -18
- package/src/audio/audio.js +4 -6
- package/src/entity/entity.js +42 -8
- package/src/geometries/ellipse.js +1 -2
- package/src/geometries/path2d.js +19 -43
- package/src/geometries/point.js +0 -5
- package/src/geometries/poly.js +1 -4
- package/src/geometries/rectangle.js +12 -8
- package/src/index.js +7 -3
- package/src/input/gamepad.js +9 -15
- package/src/input/pointerevent.js +1 -15
- package/src/level/level.js +2 -2
- package/src/level/tiled/TMXLayer.js +0 -7
- package/src/level/tiled/TMXTileMap.js +7 -3
- package/src/level/tiled/TMXTileset.js +4 -4
- package/src/loader/cache.js +16 -0
- package/src/loader/loader.js +339 -711
- package/src/loader/loadingscreen.js +3 -3
- package/src/loader/parser.js +279 -0
- package/src/loader/settings.js +85 -0
- package/src/math/color.js +8 -7
- package/src/math/matrix2.js +6 -8
- package/src/math/matrix3.js +17 -20
- package/src/math/observable_vector2.js +2 -2
- package/src/math/observable_vector3.js +2 -3
- package/src/math/vector2.js +2 -2
- package/src/math/vector3.js +2 -3
- package/src/particles/emitter.js +2 -2
- package/src/physics/body.js +17 -13
- package/src/physics/bounds.js +17 -69
- package/src/polyfill/index.js +0 -2
- package/src/renderable/container.js +24 -18
- package/src/renderable/imagelayer.js +6 -0
- package/src/renderable/renderable.js +147 -104
- package/src/renderable/sprite.js +32 -53
- package/src/renderable/ui/uitextbutton.js +0 -2
- package/src/state/state.js +1 -1
- package/src/system/device.js +1 -1
- package/src/system/pooling.js +7 -17
- package/src/text/bitmaptext.js +65 -7
- package/src/text/text.js +55 -85
- package/src/text/textstyle.js +3 -5
- package/src/utils/string.js +1 -1
- package/src/utils/utils.js +1 -3
- package/src/video/canvas/canvas_renderer.js +5 -9
- package/src/video/renderer.js +0 -11
- package/src/video/texture/atlas.js +11 -16
- package/src/video/texture/cache.js +2 -2
- package/src/video/video.js +1 -1
- package/src/video/webgl/buffer/vertex.js +20 -16
- package/src/video/webgl/compositors/compositor.js +226 -0
- package/src/video/webgl/compositors/primitive_compositor.js +68 -0
- package/src/video/webgl/compositors/quad_compositor.js +240 -0
- package/src/video/webgl/shaders/primitive.vert +2 -5
- package/src/video/webgl/shaders/quad.vert +3 -1
- package/src/video/webgl/webgl_renderer.js +137 -147
- package/dist/melonjs.mjs/_virtual/make-built-in.js +0 -10
- package/dist/melonjs.mjs/_virtual/object-define-property.js +0 -10
- package/dist/melonjs.mjs/_virtual/object-get-own-property-descriptor.js +0 -10
- package/dist/melonjs.mjs/_virtual/object-get-own-property-names.js +0 -10
- package/dist/melonjs.mjs/_virtual/object-get-own-property-symbols.js +0 -10
- package/dist/melonjs.mjs/_virtual/object-property-is-enumerable.js +0 -10
- package/dist/melonjs.mjs/_virtual/shared.js +0 -10
- package/dist/melonjs.mjs/game.js +0 -29
- package/dist/melonjs.mjs/polyfill/console.js +0 -18
- package/dist/melonjs.mjs/polyfill/performance.js +0 -27
- package/dist/melonjs.mjs/polyfill/requestAnimationFrame.js +0 -46
- package/dist/melonjs.mjs/polyfill/roundrect.js +0 -242
- package/dist/melonjs.mjs/renderable/re_container.js +0 -1016
- package/dist/melonjs.mjs/video/utils/resize.js +0 -116
- package/src/polyfill/performance.js +0 -20
- package/src/polyfill/requestAnimationFrame.js +0 -39
- package/src/video/webgl/webgl_compositor.js +0 -486
|
@@ -23,18 +23,42 @@ import Color from "./../math/color.js";
|
|
|
23
23
|
// parent constructor
|
|
24
24
|
super(x, y, width, height);
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
26
|
+
if (this.pos instanceof ObservableVector3d) {
|
|
27
|
+
this.pos.setMuted(x, y, 0).setCallback(this.updateBoundsPos, this);
|
|
28
|
+
} else {
|
|
29
|
+
/**
|
|
30
|
+
* Position of the Renderable relative to its parent container
|
|
31
|
+
* @public
|
|
32
|
+
* @type {ObservableVector3d}
|
|
33
|
+
*/
|
|
34
|
+
this.pos = pool.pull("ObservableVector3d", x, y, 0, { onUpdate: this.updateBoundsPos, scope: this});
|
|
35
|
+
}
|
|
31
36
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
37
|
+
if (this.anchorPoint instanceof ObservableVector2d) {
|
|
38
|
+
this.anchorPoint.setMuted(0.5, 0.5).setCallback(this.onAnchorUpdate, this);
|
|
39
|
+
} else {
|
|
40
|
+
/**
|
|
41
|
+
* The anchor point is used for attachment behavior, and/or when applying transformations.<br>
|
|
42
|
+
* The coordinate system places the origin at the top left corner of the frame (0, 0) and (1, 1) means the bottom-right corner<br>
|
|
43
|
+
* <img src="images/anchor_point.png"/><br>
|
|
44
|
+
* a Renderable's anchor point defaults to (0.5,0.5), which corresponds to the center position.<br>
|
|
45
|
+
* <br>
|
|
46
|
+
* <i><b>Note:</b> Object created through Tiled will have their anchorPoint set to (0, 0) to match Tiled Level editor implementation.
|
|
47
|
+
* To specify a value through Tiled, use a json expression like `json:{"x":0.5,"y":0.5}`. </i>
|
|
48
|
+
* @type {ObservableVector2d}
|
|
49
|
+
* @default <0.5,0.5>
|
|
50
|
+
*/
|
|
51
|
+
this.anchorPoint = pool.pull("ObservableVector2d", 0.5, 0.5, { onUpdate: this.onAnchorUpdate, scope: this });
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (typeof this.currentTransform === "undefined") {
|
|
55
|
+
/**
|
|
56
|
+
* the renderable default transformation matrix
|
|
57
|
+
* @type {Matrix2d}
|
|
58
|
+
*/
|
|
59
|
+
this.currentTransform = pool.pull("Matrix2d");
|
|
60
|
+
}
|
|
61
|
+
this.currentTransform.identity();
|
|
38
62
|
|
|
39
63
|
/**
|
|
40
64
|
* the renderable physic body
|
|
@@ -73,15 +97,6 @@ import Color from "./../math/color.js";
|
|
|
73
97
|
*/
|
|
74
98
|
this.body = undefined;
|
|
75
99
|
|
|
76
|
-
if (typeof this.currentTransform === "undefined") {
|
|
77
|
-
/**
|
|
78
|
-
* the renderable default transformation matrix
|
|
79
|
-
* @type {Matrix2d}
|
|
80
|
-
*/
|
|
81
|
-
this.currentTransform = pool.pull("Matrix2d");
|
|
82
|
-
}
|
|
83
|
-
this.currentTransform.identity();
|
|
84
|
-
|
|
85
100
|
/**
|
|
86
101
|
* (G)ame (U)nique (Id)entifier" <br>
|
|
87
102
|
* a GUID will be allocated for any renderable object added <br>
|
|
@@ -132,23 +147,6 @@ import Color from "./../math/color.js";
|
|
|
132
147
|
*/
|
|
133
148
|
this.floating = false;
|
|
134
149
|
|
|
135
|
-
if (this.anchorPoint instanceof ObservableVector2d) {
|
|
136
|
-
this.anchorPoint.setMuted(0.5, 0.5).setCallback(this.onAnchorUpdate, this);
|
|
137
|
-
} else {
|
|
138
|
-
/**
|
|
139
|
-
* The anchor point is used for attachment behavior, and/or when applying transformations.<br>
|
|
140
|
-
* The coordinate system places the origin at the top left corner of the frame (0, 0) and (1, 1) means the bottom-right corner<br>
|
|
141
|
-
* <img src="images/anchor_point.png"/><br>
|
|
142
|
-
* a Renderable's anchor point defaults to (0.5,0.5), which corresponds to the center position.<br>
|
|
143
|
-
* <br>
|
|
144
|
-
* <i><b>Note:</b> Object created through Tiled will have their anchorPoint set to (0, 0) to match Tiled Level editor implementation.
|
|
145
|
-
* To specify a value through Tiled, use a json expression like `json:{"x":0.5,"y":0.5}`. </i>
|
|
146
|
-
* @type {ObservableVector2d}
|
|
147
|
-
* @default <0.5,0.5>
|
|
148
|
-
*/
|
|
149
|
-
this.anchorPoint = pool.pull("ObservableVector2d", 0.5, 0.5, { onUpdate: this.onAnchorUpdate, scope: this });
|
|
150
|
-
}
|
|
151
|
-
|
|
152
150
|
/**
|
|
153
151
|
* When enabled, an object container will automatically apply
|
|
154
152
|
* any defined transformation before calling the child draw method.
|
|
@@ -208,6 +206,13 @@ import Color from "./../math/color.js";
|
|
|
208
206
|
*/
|
|
209
207
|
this.mask = undefined;
|
|
210
208
|
|
|
209
|
+
/**
|
|
210
|
+
* (Experimental) an optional shader, to be used instead of the default built-in one, when drawing this renderable (WebGL only)
|
|
211
|
+
* @type {GLShader}
|
|
212
|
+
* @default undefined
|
|
213
|
+
*/
|
|
214
|
+
this.shader = undefined;
|
|
215
|
+
|
|
211
216
|
/**
|
|
212
217
|
* the blend mode to be applied to this renderable (see renderer setBlendMode for available blend mode)
|
|
213
218
|
* @type {string}
|
|
@@ -224,23 +229,25 @@ import Color from "./../math/color.js";
|
|
|
224
229
|
*/
|
|
225
230
|
this.name = "";
|
|
226
231
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
232
|
+
/**
|
|
233
|
+
* to identify the object as a renderable object
|
|
234
|
+
* @ignore
|
|
235
|
+
*/
|
|
236
|
+
this.isRenderable = true;
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* If true then physic collision and input events will not impact this renderable
|
|
240
|
+
* @type {boolean}
|
|
241
|
+
* @default true
|
|
242
|
+
*/
|
|
243
|
+
this.isKinematic = true;
|
|
237
244
|
|
|
238
245
|
/**
|
|
239
246
|
* when true the renderable will be redrawn during the next update cycle
|
|
240
247
|
* @type {boolean}
|
|
241
|
-
* @default
|
|
248
|
+
* @default true
|
|
242
249
|
*/
|
|
243
|
-
this.isDirty =
|
|
250
|
+
this.isDirty = true;
|
|
244
251
|
|
|
245
252
|
// keep track of when we flip
|
|
246
253
|
this._flip = {
|
|
@@ -337,7 +344,7 @@ import Color from "./../math/color.js";
|
|
|
337
344
|
if (typeof this._bounds === "undefined") {
|
|
338
345
|
super.getBounds();
|
|
339
346
|
if (this.isFinite()) {
|
|
340
|
-
this.
|
|
347
|
+
this.updateBounds();
|
|
341
348
|
} else {
|
|
342
349
|
// e.g. containers or game world can have infinite size
|
|
343
350
|
this._bounds.setMinMax(this.pos.x, this.pos.y, this.width, this.height);
|
|
@@ -377,8 +384,11 @@ import Color from "./../math/color.js";
|
|
|
377
384
|
* @returns {Renderable} Reference to this object for method chaining
|
|
378
385
|
*/
|
|
379
386
|
flipX(flip = true) {
|
|
380
|
-
this.
|
|
381
|
-
|
|
387
|
+
if (this.isFlippedX !== flip) {
|
|
388
|
+
this._flip.x = !!flip;
|
|
389
|
+
this.scale(-1, 1);
|
|
390
|
+
this.isDirty = true;
|
|
391
|
+
}
|
|
382
392
|
return this;
|
|
383
393
|
}
|
|
384
394
|
|
|
@@ -389,8 +399,11 @@ import Color from "./../math/color.js";
|
|
|
389
399
|
* @returns {Renderable} Reference to this object for method chaining
|
|
390
400
|
*/
|
|
391
401
|
flipY(flip = true) {
|
|
392
|
-
this.
|
|
393
|
-
|
|
402
|
+
if (this.isFlippedY !== flip) {
|
|
403
|
+
this._flip.y = !!flip;
|
|
404
|
+
this.scale(1, -1);
|
|
405
|
+
this.isDirty = true;
|
|
406
|
+
}
|
|
394
407
|
return this;
|
|
395
408
|
}
|
|
396
409
|
|
|
@@ -402,8 +415,7 @@ import Color from "./../math/color.js";
|
|
|
402
415
|
*/
|
|
403
416
|
transform(m) {
|
|
404
417
|
this.currentTransform.multiply(m);
|
|
405
|
-
|
|
406
|
-
this.updateBoundsPos(this.pos.x, this.pos.y);
|
|
418
|
+
this.updateBounds();
|
|
407
419
|
this.isDirty = true;
|
|
408
420
|
return this;
|
|
409
421
|
}
|
|
@@ -478,9 +490,9 @@ import Color from "./../math/color.js";
|
|
|
478
490
|
* @returns {Renderable} Reference to this object for method chaining
|
|
479
491
|
*/
|
|
480
492
|
rotate(angle, v) {
|
|
481
|
-
if (
|
|
493
|
+
if (angle !== 0) {
|
|
482
494
|
this.currentTransform.rotate(angle, v);
|
|
483
|
-
|
|
495
|
+
this.updateBounds();
|
|
484
496
|
this.isDirty = true;
|
|
485
497
|
}
|
|
486
498
|
return this;
|
|
@@ -496,9 +508,9 @@ import Color from "./../math/color.js";
|
|
|
496
508
|
* @param {number} [y=x] - a number representing the ordinate of the scaling vector.
|
|
497
509
|
* @returns {Renderable} Reference to this object for method chaining
|
|
498
510
|
*/
|
|
499
|
-
scale(x, y) {
|
|
511
|
+
scale(x, y = x) {
|
|
500
512
|
this.currentTransform.scale(x, y);
|
|
501
|
-
|
|
513
|
+
this.updateBounds();
|
|
502
514
|
this.isDirty = true;
|
|
503
515
|
return this;
|
|
504
516
|
}
|
|
@@ -524,44 +536,68 @@ import Color from "./../math/color.js";
|
|
|
524
536
|
|
|
525
537
|
/**
|
|
526
538
|
* update the bounding box for this shape.
|
|
527
|
-
* @
|
|
539
|
+
* @param {boolean} [absolute=true] - update the bounds size and position in (world) absolute coordinates
|
|
528
540
|
* @returns {Bounds} this shape bounding box Rectangle object
|
|
529
541
|
*/
|
|
530
|
-
updateBounds() {
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
542
|
+
updateBounds(absolute = true) {
|
|
543
|
+
if (this.isRenderable) {
|
|
544
|
+
var bounds = this.getBounds();
|
|
545
|
+
|
|
546
|
+
bounds.clear();
|
|
547
|
+
|
|
548
|
+
if ((this.autoTransform === true) && (!this.currentTransform.isIdentity())) {
|
|
549
|
+
// temporarly translate the matrix based on the anchor point
|
|
550
|
+
this.currentTransform.translate(
|
|
551
|
+
-this.width * this.anchorPoint.x,
|
|
552
|
+
-this.height * this.anchorPoint.y
|
|
553
|
+
);
|
|
554
|
+
bounds.addFrame(
|
|
555
|
+
0,
|
|
556
|
+
0,
|
|
557
|
+
this.width,
|
|
558
|
+
this.height,
|
|
559
|
+
this.currentTransform
|
|
560
|
+
);
|
|
561
|
+
this.currentTransform.translate(
|
|
562
|
+
this.width * this.anchorPoint.x,
|
|
563
|
+
this.height * this.anchorPoint.y
|
|
564
|
+
);
|
|
565
|
+
} else {
|
|
566
|
+
bounds.addFrame(
|
|
567
|
+
0,
|
|
568
|
+
0,
|
|
569
|
+
this.width,
|
|
570
|
+
this.height
|
|
571
|
+
);
|
|
572
|
+
// translate the bounds based on the anchor point
|
|
573
|
+
bounds.translate(
|
|
574
|
+
-this.width * this.anchorPoint.x,
|
|
575
|
+
-this.height * this.anchorPoint.y
|
|
576
|
+
);
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
if (absolute === true) {
|
|
580
|
+
bounds.centerOn(this.pos.x + bounds.x + bounds.width / 2, this.pos.y + bounds.y + bounds.height / 2);
|
|
581
|
+
if (typeof this.ancestor !== "undefined" && typeof this.ancestor.addChild === "function" && this.floating !== true) {
|
|
582
|
+
bounds.translate(this.ancestor.getAbsolutePosition());
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
}
|
|
586
|
+
return bounds;
|
|
587
|
+
|
|
588
|
+
} else {
|
|
589
|
+
// manage the case where updateBounds is called
|
|
590
|
+
// before the object being yet properly initialized
|
|
591
|
+
return super.updateBounds(absolute);
|
|
592
|
+
}
|
|
534
593
|
}
|
|
535
594
|
|
|
536
595
|
/**
|
|
537
596
|
* update the renderable's bounding rect (private)
|
|
538
597
|
* @ignore
|
|
539
598
|
*/
|
|
540
|
-
updateBoundsPos(newX, newY) {
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
bounds.shift(newX, newY);
|
|
544
|
-
|
|
545
|
-
if (typeof this.anchorPoint !== "undefined" && bounds.isFinite()) {
|
|
546
|
-
bounds.translate(
|
|
547
|
-
-(this.anchorPoint.x * bounds.width),
|
|
548
|
-
-(this.anchorPoint.y * bounds.height)
|
|
549
|
-
);
|
|
550
|
-
}
|
|
551
|
-
|
|
552
|
-
/*
|
|
553
|
-
if (typeof this.body !== "undefined") {
|
|
554
|
-
var bodyBounds = this.body.getBounds();
|
|
555
|
-
bounds.translate(bodyBounds.x, bodyBounds.y);
|
|
556
|
-
}
|
|
557
|
-
*/
|
|
558
|
-
|
|
559
|
-
// XXX: This is called from the constructor, before it gets an ancestor
|
|
560
|
-
if (typeof this.ancestor !== "undefined" && typeof this.ancestor.addChild === "function" && this.floating !== true) {
|
|
561
|
-
bounds.translate(this.ancestor.getAbsolutePosition());
|
|
562
|
-
}
|
|
563
|
-
|
|
564
|
-
this.isDirty = true;
|
|
599
|
+
updateBoundsPos(newX = this.pos.x, newY = this.pos.y) {
|
|
600
|
+
this.getBounds().translate(newX - this.pos.x, newY - this.pos.y);
|
|
565
601
|
}
|
|
566
602
|
|
|
567
603
|
/**
|
|
@@ -591,7 +627,8 @@ import Color from "./../math/color.js";
|
|
|
591
627
|
// manually update the anchor point (required for updateBoundsPos)
|
|
592
628
|
this.anchorPoint.setMuted(x, y);
|
|
593
629
|
// then call updateBounds
|
|
594
|
-
this.
|
|
630
|
+
this.updateBounds();
|
|
631
|
+
this.isDirty = true;
|
|
595
632
|
}
|
|
596
633
|
|
|
597
634
|
/**
|
|
@@ -602,9 +639,8 @@ import Color from "./../math/color.js";
|
|
|
602
639
|
* @param {CanvasRenderer|WebGLRenderer} renderer - a renderer object
|
|
603
640
|
*/
|
|
604
641
|
preDraw(renderer) {
|
|
605
|
-
var
|
|
606
|
-
|
|
607
|
-
ay = bounds.height * this.anchorPoint.y;
|
|
642
|
+
var ax = this.width * this.anchorPoint.x,
|
|
643
|
+
ay = this.height * this.anchorPoint.y;
|
|
608
644
|
|
|
609
645
|
// save renderer context
|
|
610
646
|
renderer.save();
|
|
@@ -612,16 +648,6 @@ import Color from "./../math/color.js";
|
|
|
612
648
|
// apply the defined alpha value
|
|
613
649
|
renderer.setGlobalAlpha(renderer.globalAlpha() * this.getOpacity());
|
|
614
650
|
|
|
615
|
-
// apply flip
|
|
616
|
-
if (this._flip.x || this._flip.y) {
|
|
617
|
-
var dx = this._flip.x ? this.centerX - ax : 0,
|
|
618
|
-
dy = this._flip.y ? this.centerY - ay : 0;
|
|
619
|
-
|
|
620
|
-
renderer.translate(dx, dy);
|
|
621
|
-
renderer.scale(this._flip.x ? -1 : 1, this._flip.y ? -1 : 1);
|
|
622
|
-
renderer.translate(-dx, -dy);
|
|
623
|
-
}
|
|
624
|
-
|
|
625
651
|
// apply stencil mask if defined
|
|
626
652
|
if (typeof this.mask !== "undefined") {
|
|
627
653
|
renderer.translate(this.pos.x, this.pos.y);
|
|
@@ -629,6 +655,11 @@ import Color from "./../math/color.js";
|
|
|
629
655
|
renderer.translate(-this.pos.x, -this.pos.y);
|
|
630
656
|
}
|
|
631
657
|
|
|
658
|
+
// use this renderable shader if defined
|
|
659
|
+
if (typeof this.shader === "object" && typeof renderer.gl !== "undefined") {
|
|
660
|
+
renderer.customShader = this.shader;
|
|
661
|
+
}
|
|
662
|
+
|
|
632
663
|
if ((this.autoTransform === true) && (!this.currentTransform.isIdentity())) {
|
|
633
664
|
// apply the renderable transformation matrix
|
|
634
665
|
renderer.translate(this.pos.x, this.pos.y);
|
|
@@ -680,6 +711,12 @@ import Color from "./../math/color.js";
|
|
|
680
711
|
renderer.clearMask();
|
|
681
712
|
}
|
|
682
713
|
|
|
714
|
+
// revert to the default shader if defined
|
|
715
|
+
if (typeof this.shader === "object" && typeof renderer.gl !== "undefined") {
|
|
716
|
+
renderer.customShader = undefined;
|
|
717
|
+
//renderer.setCompositor("quad");
|
|
718
|
+
}
|
|
719
|
+
|
|
683
720
|
// restore the context
|
|
684
721
|
renderer.restore();
|
|
685
722
|
|
|
@@ -759,6 +796,12 @@ import Color from "./../math/color.js";
|
|
|
759
796
|
|
|
760
797
|
// call the user defined destroy method
|
|
761
798
|
this.onDestroyEvent.apply(this, arguments);
|
|
799
|
+
|
|
800
|
+
// destroy any shader object if not done by the user through onDestroyEvent()
|
|
801
|
+
if (typeof this.shader === "object") {
|
|
802
|
+
this.shader.destroy();
|
|
803
|
+
this.shader = undefined;
|
|
804
|
+
}
|
|
762
805
|
}
|
|
763
806
|
|
|
764
807
|
/**
|
package/src/renderable/sprite.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { renderer } from "./../video/video.js";
|
|
2
2
|
import pool from "./../system/pooling.js";
|
|
3
|
-
import
|
|
3
|
+
import { getImage } from "./../loader/loader.js";
|
|
4
4
|
import { TextureAtlas } from "./../video/texture/atlas.js";
|
|
5
5
|
import Renderable from "./renderable.js";
|
|
6
6
|
import Color from "../math/color.js";
|
|
@@ -95,7 +95,7 @@ import Color from "../math/color.js";
|
|
|
95
95
|
// (reusing current, any better/cleaner place?)
|
|
96
96
|
this.current = {
|
|
97
97
|
// the current animation name
|
|
98
|
-
name :
|
|
98
|
+
name : undefined,
|
|
99
99
|
// length of the current animation name
|
|
100
100
|
length : 0,
|
|
101
101
|
//current frame texture offset
|
|
@@ -132,9 +132,6 @@ import Color from "../math/color.js";
|
|
|
132
132
|
if (region) {
|
|
133
133
|
// set the sprite region within the texture
|
|
134
134
|
this.setRegion(region);
|
|
135
|
-
// update the default "current" frame size
|
|
136
|
-
this.current.width = settings.framewidth || region.width;
|
|
137
|
-
this.current.height = settings.frameheight || region.height;
|
|
138
135
|
} else {
|
|
139
136
|
// throw an error
|
|
140
137
|
throw new Error("Texture - region for " + settings.region + " not found");
|
|
@@ -142,14 +139,14 @@ import Color from "../math/color.js";
|
|
|
142
139
|
}
|
|
143
140
|
} else {
|
|
144
141
|
// HTMLImageElement/Canvas or {string}
|
|
145
|
-
this.image = (typeof settings.image === "object") ? settings.image :
|
|
142
|
+
this.image = (typeof settings.image === "object") ? settings.image : getImage(settings.image);
|
|
146
143
|
// throw an error if image ends up being null/undefined
|
|
147
144
|
if (!this.image) {
|
|
148
145
|
throw new Error("me.Sprite: '" + settings.image + "' image/texture not found!");
|
|
149
146
|
}
|
|
150
147
|
// update the default "current" frame size
|
|
151
|
-
this.current.width = settings.framewidth = settings.framewidth || this.image.width;
|
|
152
|
-
this.current.height = settings.frameheight = settings.frameheight || this.image.height;
|
|
148
|
+
this.width = this.current.width = settings.framewidth = settings.framewidth || this.image.width;
|
|
149
|
+
this.height = this.current.height = settings.frameheight = settings.frameheight || this.image.height;
|
|
153
150
|
this.source = renderer.cache.get(this.image, settings);
|
|
154
151
|
this.textureAtlas = this.source.getAtlas();
|
|
155
152
|
}
|
|
@@ -160,10 +157,6 @@ import Color from "../math/color.js";
|
|
|
160
157
|
this.atlasIndices = settings.atlasIndices;
|
|
161
158
|
}
|
|
162
159
|
|
|
163
|
-
// resize based on the active frame
|
|
164
|
-
this.width = this.current.width;
|
|
165
|
-
this.height = this.current.height;
|
|
166
|
-
|
|
167
160
|
// apply flip flags if specified
|
|
168
161
|
if (typeof (settings.flipX) !== "undefined") {
|
|
169
162
|
this.flipX(!!settings.flipX);
|
|
@@ -202,14 +195,11 @@ import Color from "../math/color.js";
|
|
|
202
195
|
this.pos.z = settings.z;
|
|
203
196
|
}
|
|
204
197
|
|
|
205
|
-
//
|
|
198
|
+
// addAnimation will return 0 if no texture atlas is defined
|
|
206
199
|
if (this.addAnimation("default", null) !== 0) {
|
|
207
200
|
// set as default
|
|
208
201
|
this.setCurrentAnimation("default");
|
|
209
202
|
}
|
|
210
|
-
|
|
211
|
-
// enable currentTransform for me.Sprite based objects
|
|
212
|
-
this.autoTransform = true;
|
|
213
203
|
}
|
|
214
204
|
|
|
215
205
|
/**
|
|
@@ -389,22 +379,24 @@ import Color from "../math/color.js";
|
|
|
389
379
|
* return false; // do not reset to first frame
|
|
390
380
|
* }).bind(this));
|
|
391
381
|
*/
|
|
392
|
-
setCurrentAnimation(name, resetAnim, preserve_dt) {
|
|
393
|
-
if (this.anim[name]) {
|
|
394
|
-
this.
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
382
|
+
setCurrentAnimation(name, resetAnim, preserve_dt = false) {
|
|
383
|
+
if (typeof this.anim[name] !== "undefined") {
|
|
384
|
+
if (!this.isCurrentAnimation(name)) {
|
|
385
|
+
this.current.name = name;
|
|
386
|
+
this.current.length = this.anim[this.current.name].length;
|
|
387
|
+
if (typeof resetAnim === "string") {
|
|
388
|
+
this.resetAnim = this.setCurrentAnimation.bind(this, resetAnim, null, true);
|
|
389
|
+
} else if (typeof resetAnim === "function") {
|
|
390
|
+
this.resetAnim = resetAnim;
|
|
391
|
+
} else {
|
|
392
|
+
this.resetAnim = undefined;
|
|
393
|
+
}
|
|
394
|
+
this.setAnimationFrame(0);
|
|
395
|
+
if (!preserve_dt) {
|
|
396
|
+
this.dt = 0;
|
|
397
|
+
}
|
|
398
|
+
this.isDirty = true;
|
|
406
399
|
}
|
|
407
|
-
this.isDirty = true;
|
|
408
400
|
} else {
|
|
409
401
|
throw new Error("animation id '" + name + "' not defined");
|
|
410
402
|
}
|
|
@@ -461,17 +453,19 @@ import Color from "../math/color.js";
|
|
|
461
453
|
// set the sprite offset within the texture
|
|
462
454
|
this.current.offset.setV(region.offset);
|
|
463
455
|
// set angle if defined
|
|
464
|
-
this.current.angle = region.angle;
|
|
456
|
+
this.current.angle = typeof region.angle === "number" ? region.angle : 0;
|
|
465
457
|
// update the default "current" size
|
|
466
458
|
this.width = this.current.width = region.width;
|
|
467
459
|
this.height = this.current.height = region.height;
|
|
468
460
|
// set global anchortPoint if defined
|
|
469
461
|
if (region.anchorPoint) {
|
|
470
|
-
this.anchorPoint.
|
|
462
|
+
this.anchorPoint.setMuted(
|
|
471
463
|
this._flip.x && region.trimmed === true ? 1 - region.anchorPoint.x : region.anchorPoint.x,
|
|
472
464
|
this._flip.y && region.trimmed === true ? 1 - region.anchorPoint.y : region.anchorPoint.y
|
|
473
465
|
);
|
|
474
466
|
}
|
|
467
|
+
// update the sprite bounding box
|
|
468
|
+
this.updateBounds();
|
|
475
469
|
this.isDirty = true;
|
|
476
470
|
return this;
|
|
477
471
|
}
|
|
@@ -480,14 +474,14 @@ import Color from "../math/color.js";
|
|
|
480
474
|
* force the current animation frame index.
|
|
481
475
|
* @name setAnimationFrame
|
|
482
476
|
* @memberof Sprite
|
|
483
|
-
* @param {number} [
|
|
477
|
+
* @param {number} [index=0] - animation frame index
|
|
484
478
|
* @returns {Sprite} Reference to this object for method chaining
|
|
485
479
|
* @example
|
|
486
480
|
* // reset the current animation to the first frame
|
|
487
481
|
* this.setAnimationFrame();
|
|
488
482
|
*/
|
|
489
|
-
setAnimationFrame(
|
|
490
|
-
this.current.idx =
|
|
483
|
+
setAnimationFrame(index = 0) {
|
|
484
|
+
this.current.idx = index % this.current.length;
|
|
491
485
|
return this.setRegion(this.getAnimationFrameObjectByIndex(this.current.idx));
|
|
492
486
|
}
|
|
493
487
|
|
|
@@ -524,14 +518,14 @@ import Color from "../math/color.js";
|
|
|
524
518
|
*/
|
|
525
519
|
update(dt) {
|
|
526
520
|
// Update animation if necessary
|
|
527
|
-
if (!this.animationpause && this.current
|
|
521
|
+
if (!this.animationpause && this.current.length > 1) {
|
|
528
522
|
var duration = this.getAnimationFrameObjectByIndex(this.current.idx).delay;
|
|
529
523
|
this.dt += dt;
|
|
530
524
|
while (this.dt >= duration) {
|
|
531
525
|
this.isDirty = true;
|
|
532
526
|
this.dt -= duration;
|
|
533
527
|
|
|
534
|
-
var nextFrame = (this.current.length > 1? this.current.idx+1: this.current.idx);
|
|
528
|
+
var nextFrame = (this.current.length > 1 ? this.current.idx + 1 : this.current.idx);
|
|
535
529
|
this.setAnimationFrame(nextFrame);
|
|
536
530
|
|
|
537
531
|
// Switch animation if we reach the end of the strip and a callback is defined
|
|
@@ -551,21 +545,6 @@ import Color from "../math/color.js";
|
|
|
551
545
|
}
|
|
552
546
|
}
|
|
553
547
|
|
|
554
|
-
// update the sprite bounding box
|
|
555
|
-
/*
|
|
556
|
-
if (this.isDirty === true && !this.currentTransform.isIdentity()) {
|
|
557
|
-
this.getBounds().clear();
|
|
558
|
-
this.getBounds().addFrame(
|
|
559
|
-
0,
|
|
560
|
-
0,
|
|
561
|
-
this.current.width,
|
|
562
|
-
this.current.height,
|
|
563
|
-
this.currentTransform
|
|
564
|
-
);
|
|
565
|
-
this.updateBoundsPos(this.pos.x, this.pos.y);
|
|
566
|
-
}
|
|
567
|
-
*/
|
|
568
|
-
|
|
569
548
|
//update the "flickering" state if necessary
|
|
570
549
|
if (this._flicker.isFlickering) {
|
|
571
550
|
this._flicker.duration -= dt;
|
|
@@ -24,7 +24,6 @@ import UIBaseElement from "./uibaseelement.js";
|
|
|
24
24
|
* @param {string} [settings.backgroundColor] - The css value of a background color
|
|
25
25
|
* @param {string} [settings.hoverColor] - The css value of a color to be used if the pointer hovers over the button
|
|
26
26
|
* @param {string} [settings.borderStrokeColor] - The css value of a color to be used to draw the border
|
|
27
|
-
* @param {boolean} [settings.offScreenCanvas] - Weather to use an offScreen canvas or not
|
|
28
27
|
* @param {string} [settings.fillStyle] - The css value of a tint color to be used to tint the text
|
|
29
28
|
* @param {number} [settings.borderWidth] - Width of the button
|
|
30
29
|
* @param {number} [settings.borderHeight] - Height of the button
|
|
@@ -57,7 +56,6 @@ import UIBaseElement from "./uibaseelement.js";
|
|
|
57
56
|
settings.backgroundColor = settings.backgroundColor || "#00aa00";
|
|
58
57
|
settings.hoverColor = settings.hoverColor || "#00ff00";
|
|
59
58
|
settings.borderStrokeColor = settings.borderStrokeColor || "#000000";
|
|
60
|
-
settings.offScreenCanvas = settings.offScreenCanvas || false;
|
|
61
59
|
settings.fillStyle = settings.fillStyle || "#ffffff";
|
|
62
60
|
settings.lineWidth = settings.lineWidth || 1;
|
|
63
61
|
settings.anchorPoint = settings.anchorPoint || new Vector2d(0, 0);
|
package/src/state/state.js
CHANGED
|
@@ -520,7 +520,7 @@ var state = {
|
|
|
520
520
|
},
|
|
521
521
|
|
|
522
522
|
/**
|
|
523
|
-
* enable/disable transition
|
|
523
|
+
* enable/disable the transition to a particular state (by default enabled for all)
|
|
524
524
|
* @name setTransition
|
|
525
525
|
* @memberof state
|
|
526
526
|
* @public
|
package/src/system/device.js
CHANGED
|
@@ -100,7 +100,7 @@ export const pointerEvent = !!globalThis.PointerEvent;
|
|
|
100
100
|
* @readonly
|
|
101
101
|
* @public
|
|
102
102
|
*/
|
|
103
|
-
export const touch = touchEvent || pointerEvent;
|
|
103
|
+
export const touch = touchEvent || (pointerEvent && globalThis.navigator.maxTouchPoints > 0);
|
|
104
104
|
|
|
105
105
|
/**
|
|
106
106
|
* the maximum number of simultaneous touch contact points are supported by the current device.
|
package/src/system/pooling.js
CHANGED
|
@@ -28,14 +28,14 @@ class ObjectPool {
|
|
|
28
28
|
* @param {boolean} [recycling=false] - enables object recycling for the specified class
|
|
29
29
|
* @example
|
|
30
30
|
* // implement CherryEntity
|
|
31
|
-
* class
|
|
31
|
+
* class Cherry extends Sprite {
|
|
32
32
|
* onResetEvent() {
|
|
33
33
|
* // reset object mutable properties
|
|
34
34
|
* this.lifeBar = 100;
|
|
35
35
|
* }
|
|
36
36
|
* };
|
|
37
37
|
* // add our users defined entities in the object pool and enable object recycling
|
|
38
|
-
* me.pool.register("
|
|
38
|
+
* me.pool.register("cherrysprite", Cherry, true);
|
|
39
39
|
*/
|
|
40
40
|
register(className, classObj, recycling = false) {
|
|
41
41
|
if (typeof (classObj) !== "undefined") {
|
|
@@ -69,11 +69,7 @@ class ObjectPool {
|
|
|
69
69
|
* me.game.world.removeChild(enemy);
|
|
70
70
|
* me.game.world.removeChild(bullet);
|
|
71
71
|
*/
|
|
72
|
-
pull(name) {
|
|
73
|
-
var args = new Array(arguments.length);
|
|
74
|
-
for (var i = 0; i < arguments.length; i++) {
|
|
75
|
-
args[i] = arguments[i];
|
|
76
|
-
}
|
|
72
|
+
pull(name, ...args) {
|
|
77
73
|
var className = this.objectClass[name];
|
|
78
74
|
if (className) {
|
|
79
75
|
var proto = className["class"],
|
|
@@ -81,18 +77,12 @@ class ObjectPool {
|
|
|
81
77
|
obj;
|
|
82
78
|
|
|
83
79
|
if (poolArray && ((obj = poolArray.pop()))) {
|
|
84
|
-
//
|
|
85
|
-
|
|
86
|
-
// call the object onResetEvent function if defined
|
|
87
|
-
if (typeof(obj.onResetEvent) === "function") {
|
|
88
|
-
obj.onResetEvent.apply(obj, args);
|
|
89
|
-
}
|
|
80
|
+
// poolable object must implement a `onResetEvent` method
|
|
81
|
+
obj.onResetEvent.apply(obj, args);
|
|
90
82
|
this.instance_counter--;
|
|
91
|
-
}
|
|
92
|
-
else {
|
|
83
|
+
} else {
|
|
93
84
|
// create a new instance
|
|
94
|
-
|
|
95
|
-
obj = new (proto.bind.apply(proto, args))();
|
|
85
|
+
obj = new (proto.bind.apply(proto, [ proto, ...args ]))();
|
|
96
86
|
if (poolArray) {
|
|
97
87
|
obj.className = name;
|
|
98
88
|
}
|