melonjs 15.0.0 → 15.1.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 +4 -4
- 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 +7 -3
- 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 +27 -17
- package/dist/melonjs.mjs/application/header.js +6 -5
- package/dist/melonjs.mjs/application/resize.js +20 -20
- package/dist/melonjs.mjs/application/settings.js +1 -1
- package/dist/melonjs.mjs/audio/audio.js +17 -17
- package/dist/melonjs.mjs/camera/camera2d.js +10 -10
- package/dist/melonjs.mjs/const.js +1 -1
- package/dist/melonjs.mjs/entity/entity.js +4 -4
- package/dist/melonjs.mjs/geometries/ellipse.js +6 -6
- package/dist/melonjs.mjs/geometries/line.js +9 -9
- package/dist/melonjs.mjs/geometries/path2d.js +53 -53
- package/dist/melonjs.mjs/geometries/point.js +2 -2
- package/dist/melonjs.mjs/geometries/poly.js +29 -29
- package/dist/melonjs.mjs/geometries/rectangle.js +8 -8
- package/dist/melonjs.mjs/geometries/roundrect.js +6 -6
- package/dist/melonjs.mjs/index.js +5 -5
- package/dist/melonjs.mjs/input/gamepad.js +30 -30
- package/dist/melonjs.mjs/input/input.js +2 -2
- package/dist/melonjs.mjs/input/keyboard.js +15 -15
- package/dist/melonjs.mjs/input/pointer.js +2 -2
- package/dist/melonjs.mjs/input/pointerevent.js +58 -58
- package/dist/melonjs.mjs/lang/console.js +3 -3
- package/dist/melonjs.mjs/lang/deprecated.js +2 -2
- package/dist/melonjs.mjs/level/level.js +9 -9
- package/dist/melonjs.mjs/level/tiled/TMXGroup.js +3 -3
- package/dist/melonjs.mjs/level/tiled/TMXLayer.js +31 -31
- package/dist/melonjs.mjs/level/tiled/TMXObject.js +8 -8
- package/dist/melonjs.mjs/level/tiled/TMXTile.js +8 -8
- package/dist/melonjs.mjs/level/tiled/TMXTileMap.js +19 -19
- package/dist/melonjs.mjs/level/tiled/TMXTileset.js +15 -15
- package/dist/melonjs.mjs/level/tiled/TMXTilesetGroup.js +3 -3
- package/dist/melonjs.mjs/level/tiled/TMXUtils.js +46 -41
- package/dist/melonjs.mjs/level/tiled/constants.js +1 -1
- package/dist/melonjs.mjs/level/tiled/renderer/TMXHexagonalRenderer.js +30 -30
- package/dist/melonjs.mjs/level/tiled/renderer/TMXIsometricRenderer.js +21 -21
- package/dist/melonjs.mjs/level/tiled/renderer/TMXOrthogonalRenderer.js +10 -10
- package/dist/melonjs.mjs/level/tiled/renderer/TMXRenderer.js +2 -2
- package/dist/melonjs.mjs/level/tiled/renderer/TMXStaggeredRenderer.js +6 -6
- package/dist/melonjs.mjs/level/tiled/renderer/autodetect.js +1 -1
- package/dist/melonjs.mjs/loader/cache.js +1 -1
- package/dist/melonjs.mjs/loader/loader.js +7 -7
- package/dist/melonjs.mjs/loader/loadingscreen.js +2 -2
- package/dist/melonjs.mjs/loader/melonjs_logo.png.js +1 -1
- package/dist/melonjs.mjs/loader/parser.js +13 -13
- package/dist/melonjs.mjs/loader/settings.js +3 -3
- package/dist/melonjs.mjs/math/color.js +21 -21
- package/dist/melonjs.mjs/math/math.js +2 -2
- package/dist/melonjs.mjs/math/matrix2.js +22 -22
- package/dist/melonjs.mjs/math/matrix3.js +52 -52
- package/dist/melonjs.mjs/math/observable_vector2.js +12 -12
- package/dist/melonjs.mjs/math/observable_vector3.js +22 -22
- package/dist/melonjs.mjs/math/vector2.js +11 -11
- package/dist/melonjs.mjs/math/vector3.js +21 -21
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/esm/arraymultimap.js +45 -0
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/esm/multimap.js +130 -0
- 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 +2 -2
- 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 +5 -5
- package/dist/melonjs.mjs/particles/particle.js +8 -8
- package/dist/melonjs.mjs/particles/settings.js +3 -3
- package/dist/melonjs.mjs/physics/body.js +17 -17
- package/dist/melonjs.mjs/physics/bounds.js +12 -12
- package/dist/melonjs.mjs/physics/collision.js +3 -3
- package/dist/melonjs.mjs/physics/detector.js +14 -14
- package/dist/melonjs.mjs/physics/quadtree.js +19 -19
- package/dist/melonjs.mjs/physics/response.js +1 -1
- package/dist/melonjs.mjs/physics/sat.js +60 -60
- package/dist/melonjs.mjs/physics/world.js +4 -4
- package/dist/melonjs.mjs/plugin/plugin.js +11 -11
- package/dist/melonjs.mjs/renderable/collectable.js +2 -2
- package/dist/melonjs.mjs/renderable/colorlayer.js +1 -1
- package/dist/melonjs.mjs/renderable/container.js +77 -59
- package/dist/melonjs.mjs/renderable/dragndrop.js +5 -5
- package/dist/melonjs.mjs/renderable/imagelayer.js +7 -6
- package/dist/melonjs.mjs/renderable/light2d.js +6 -6
- package/dist/melonjs.mjs/renderable/nineslicesprite.js +12 -12
- package/dist/melonjs.mjs/renderable/renderable.js +11 -11
- package/dist/melonjs.mjs/renderable/sprite.js +25 -25
- package/dist/melonjs.mjs/renderable/trigger.js +11 -9
- package/dist/melonjs.mjs/renderable/ui/uibaseelement.js +97 -27
- package/dist/melonjs.mjs/renderable/ui/uispriteelement.js +25 -25
- package/dist/melonjs.mjs/renderable/ui/uitextbutton.js +83 -63
- package/dist/melonjs.mjs/state/stage.js +7 -7
- package/dist/melonjs.mjs/state/state.js +15 -15
- 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 +2 -2
- package/dist/melonjs.mjs/system/platform.js +1 -1
- package/dist/melonjs.mjs/system/pooling.js +9 -9
- package/dist/melonjs.mjs/system/save.js +6 -6
- package/dist/melonjs.mjs/system/timer.js +16 -12
- package/dist/melonjs.mjs/text/bitmaptext.js +20 -20
- package/dist/melonjs.mjs/text/bitmaptextdata.js +22 -22
- package/dist/melonjs.mjs/text/glyph.js +3 -3
- package/dist/melonjs.mjs/text/text.js +10 -9
- package/dist/melonjs.mjs/text/textmetrics.js +15 -15
- package/dist/melonjs.mjs/text/textstyle.js +1 -1
- package/dist/melonjs.mjs/tweens/easing.js +4 -4
- package/dist/melonjs.mjs/tweens/interpolation.js +8 -8
- package/dist/melonjs.mjs/tweens/tween.js +11 -11
- package/dist/melonjs.mjs/utils/agent.js +6 -6
- package/dist/melonjs.mjs/utils/array.js +4 -4
- package/dist/melonjs.mjs/utils/file.js +1 -1
- package/dist/melonjs.mjs/utils/function.js +5 -5
- package/dist/melonjs.mjs/utils/string.js +3 -3
- package/dist/melonjs.mjs/utils/utils.js +16 -16
- package/dist/melonjs.mjs/video/canvas/canvas_renderer.js +35 -109
- package/dist/melonjs.mjs/video/renderer.js +74 -7
- package/dist/melonjs.mjs/video/texture/atlas.js +37 -37
- package/dist/melonjs.mjs/video/texture/cache.js +9 -10
- package/dist/melonjs.mjs/video/texture/canvas_texture.js +63 -3
- 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 +3 -3
- package/dist/melonjs.mjs/video/webgl/compositors/compositor.js +5 -5
- package/dist/melonjs.mjs/video/webgl/compositors/primitive_compositor.js +5 -5
- package/dist/melonjs.mjs/video/webgl/compositors/quad_compositor.js +18 -15
- package/dist/melonjs.mjs/video/webgl/glshader.js +7 -7
- package/dist/melonjs.mjs/video/webgl/shaders/primitive.frag.js +1 -1
- package/dist/melonjs.mjs/video/webgl/shaders/primitive.vert.js +1 -1
- package/dist/melonjs.mjs/video/webgl/shaders/quad.frag.js +1 -1
- package/dist/melonjs.mjs/video/webgl/shaders/quad.vert.js +1 -1
- package/dist/melonjs.mjs/video/webgl/utils/attributes.js +2 -2
- package/dist/melonjs.mjs/video/webgl/utils/precision.js +1 -1
- package/dist/melonjs.mjs/video/webgl/utils/program.js +7 -7
- package/dist/melonjs.mjs/video/webgl/utils/string.js +1 -1
- package/dist/melonjs.mjs/video/webgl/utils/uniforms.js +4 -4
- package/dist/melonjs.mjs/video/webgl/webgl_renderer.js +55 -38
- package/dist/melonjs.module.js +1747 -1809
- package/dist/types/application/application.d.ts +11 -8
- package/dist/types/audio/audio.d.ts +3 -3
- package/dist/types/index.d.ts +4 -3
- package/dist/types/input/input.d.ts +1 -1
- package/dist/types/input/keyboard.d.ts +1 -1
- package/dist/types/input/pointerevent.d.ts +6 -6
- package/dist/types/level/level.d.ts +2 -2
- package/dist/types/level/tiled/TMXLayer.d.ts +4 -4
- package/dist/types/level/tiled/TMXTileMap.d.ts +2 -2
- package/dist/types/level/tiled/TMXUtils.d.ts +5 -4
- package/dist/types/loader/loader.d.ts +2 -2
- package/dist/types/loader/settings.d.ts +2 -2
- package/dist/types/particles/emitter.d.ts +1 -1
- package/dist/types/physics/collision.d.ts +1 -1
- package/dist/types/physics/detector.d.ts +1 -1
- package/dist/types/plugin/plugin.d.ts +2 -2
- package/dist/types/renderable/container.d.ts +21 -17
- package/dist/types/renderable/sprite.d.ts +11 -11
- package/dist/types/renderable/trigger.d.ts +1 -1
- package/dist/types/renderable/ui/uibaseelement.d.ts +28 -6
- package/dist/types/renderable/ui/uispriteelement.d.ts +12 -14
- package/dist/types/renderable/ui/uitextbutton.d.ts +52 -11
- package/dist/types/state/stage.d.ts +1 -1
- package/dist/types/system/device.d.ts +1 -1
- package/dist/types/system/pooling.d.ts +3 -3
- package/dist/types/system/timer.d.ts +5 -5
- package/dist/types/text/bitmaptext.d.ts +1 -1
- package/dist/types/text/text.d.ts +1 -1
- package/dist/types/utils/array.d.ts +2 -2
- package/dist/types/video/canvas/canvas_renderer.d.ts +8 -76
- package/dist/types/video/renderer.d.ts +48 -0
- package/dist/types/video/texture/atlas.d.ts +3 -3
- package/dist/types/video/texture/canvas_texture.d.ts +40 -0
- package/dist/types/video/webgl/glshader.d.ts +1 -1
- package/dist/types/video/webgl/webgl_renderer.d.ts +13 -9
- package/package.json +14 -14
- package/src/application/application.js +26 -16
- package/src/application/header.js +5 -4
- package/src/application/resize.js +19 -19
- package/src/audio/audio.js +16 -16
- package/src/camera/camera2d.js +9 -9
- package/src/entity/entity.js +3 -3
- package/src/geometries/ellipse.js +5 -5
- package/src/geometries/line.js +8 -8
- package/src/geometries/path2d.js +52 -52
- package/src/geometries/point.js +1 -1
- package/src/geometries/poly.js +28 -28
- package/src/geometries/rectangle.js +7 -7
- package/src/geometries/roundrect.js +5 -5
- package/src/index.js +3 -2
- package/src/input/gamepad.js +29 -29
- package/src/input/input.js +1 -1
- package/src/input/keyboard.js +14 -14
- package/src/input/pointer.js +1 -1
- package/src/input/pointerevent.js +52 -52
- package/src/lang/console.js +2 -2
- package/src/lang/deprecated.js +1 -1
- package/src/level/level.js +8 -8
- package/src/level/tiled/TMXGroup.js +2 -2
- package/src/level/tiled/TMXLayer.js +30 -30
- package/src/level/tiled/TMXObject.js +7 -7
- package/src/level/tiled/TMXTile.js +7 -7
- package/src/level/tiled/TMXTileMap.js +18 -18
- package/src/level/tiled/TMXTileset.js +14 -14
- package/src/level/tiled/TMXTilesetGroup.js +2 -2
- package/src/level/tiled/TMXUtils.js +45 -40
- package/src/level/tiled/renderer/TMXHexagonalRenderer.js +29 -29
- package/src/level/tiled/renderer/TMXIsometricRenderer.js +20 -20
- package/src/level/tiled/renderer/TMXOrthogonalRenderer.js +9 -9
- package/src/level/tiled/renderer/TMXRenderer.js +1 -1
- package/src/level/tiled/renderer/TMXStaggeredRenderer.js +5 -5
- package/src/loader/loader.js +6 -6
- package/src/loader/loadingscreen.js +1 -1
- package/src/loader/parser.js +12 -12
- package/src/loader/settings.js +2 -2
- package/src/math/color.js +20 -20
- package/src/math/math.js +1 -1
- package/src/math/matrix2.js +21 -21
- package/src/math/matrix3.js +51 -51
- package/src/math/observable_vector2.js +11 -11
- package/src/math/observable_vector3.js +21 -21
- package/src/math/vector2.js +10 -10
- package/src/math/vector3.js +20 -20
- package/src/particles/emitter.js +4 -4
- package/src/particles/particle.js +7 -7
- package/src/particles/settings.js +2 -2
- package/src/physics/body.js +16 -16
- package/src/physics/bounds.js +11 -11
- package/src/physics/collision.js +2 -2
- package/src/physics/detector.js +13 -13
- package/src/physics/quadtree.js +18 -18
- package/src/physics/sat.js +59 -59
- package/src/physics/world.js +3 -3
- package/src/plugin/plugin.js +8 -8
- package/src/renderable/collectable.js +1 -1
- package/src/renderable/container.js +76 -58
- package/src/renderable/dragndrop.js +4 -4
- package/src/renderable/imagelayer.js +6 -5
- package/src/renderable/light2d.js +5 -5
- package/src/renderable/nineslicesprite.js +11 -11
- package/src/renderable/renderable.js +10 -10
- package/src/renderable/sprite.js +24 -24
- package/src/renderable/trigger.js +10 -8
- package/src/renderable/ui/uibaseelement.js +96 -26
- package/src/renderable/ui/uispriteelement.js +24 -24
- package/src/renderable/ui/uitextbutton.js +85 -65
- package/src/state/stage.js +6 -6
- package/src/state/state.js +14 -14
- package/src/system/device.js +1 -1
- package/src/system/event.js +1 -1
- package/src/system/pooling.js +8 -8
- package/src/system/save.js +5 -5
- package/src/system/timer.js +15 -11
- package/src/text/bitmaptext.js +19 -19
- package/src/text/bitmaptextdata.js +21 -21
- package/src/text/glyph.js +2 -2
- package/src/text/text.js +9 -8
- package/src/text/textmetrics.js +14 -14
- package/src/tweens/easing.js +3 -3
- package/src/tweens/interpolation.js +7 -7
- package/src/tweens/tween.js +10 -10
- package/src/utils/agent.js +5 -5
- package/src/utils/array.js +3 -3
- package/src/utils/function.js +4 -4
- package/src/utils/string.js +2 -2
- package/src/utils/utils.js +15 -15
- package/src/video/canvas/canvas_renderer.js +34 -108
- package/src/video/renderer.js +72 -5
- package/src/video/texture/atlas.js +36 -36
- package/src/video/texture/cache.js +6 -6
- package/src/video/texture/canvas_texture.js +62 -2
- package/src/video/video.js +1 -1
- package/src/video/webgl/buffer/vertex.js +2 -2
- package/src/video/webgl/compositors/compositor.js +4 -4
- package/src/video/webgl/compositors/primitive_compositor.js +4 -4
- package/src/video/webgl/compositors/quad_compositor.js +17 -14
- package/src/video/webgl/glshader.js +6 -6
- package/src/video/webgl/utils/attributes.js +1 -1
- package/src/video/webgl/utils/program.js +6 -6
- package/src/video/webgl/utils/uniforms.js +3 -3
- package/src/video/webgl/webgl_renderer.js +54 -37
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import Vector2d from "../../math/vector2.js";
|
|
2
1
|
import BitmapText from "../../text/bitmaptext.js";
|
|
3
2
|
import RoundRect from "../../geometries/roundrect.js";
|
|
4
3
|
import UIBaseElement from "./uibaseelement.js";
|
|
@@ -11,25 +10,27 @@ import UIBaseElement from "./uibaseelement.js";
|
|
|
11
10
|
*/
|
|
12
11
|
export default class UITextButton extends UIBaseElement {
|
|
13
12
|
/**
|
|
14
|
-
* A Text Button with an outlined background border, filled with background color.
|
|
13
|
+
* A Bitmap Text Button with an outlined background border, filled with background color.
|
|
15
14
|
* It uses a RoundRect as background and changes the background color on hovering over.
|
|
16
15
|
* The background will be drawn with 0.5 opacity, so that the background of the button is
|
|
17
16
|
* slightly shining through.
|
|
18
17
|
* @param {number} x - x pos of the button
|
|
19
18
|
* @param {number} y - y pos of the button
|
|
20
19
|
* @param {string} [settings.font] - The name of the BitmapText font to use
|
|
21
|
-
* @param {number} [settings.size] - The scale factor of the
|
|
22
|
-
* @param {string} [settings.text] - The text to display
|
|
20
|
+
* @param {number} [settings.size=1] - The scale factor of the BitmapText
|
|
21
|
+
* @param {string} [settings.text] - The text to display
|
|
23
22
|
* @param {string} [settings.bindKey] - The key to bind the action to (default: none)
|
|
24
|
-
* @param {string} [settings.backgroundColor] - The css value of a background color
|
|
25
|
-
* @param {string} [settings.hoverColor] - The css value of a color to be used if the pointer hovers over the button
|
|
26
|
-
* @param {string} [settings.borderStrokeColor] - The css value of a color to be used to draw the border
|
|
27
|
-
* @param {string} [settings.fillStyle] - The css value of a tint color to be used to tint the
|
|
23
|
+
* @param {string} [settings.backgroundColor="#00aa0080"] - The css value of a background color
|
|
24
|
+
* @param {string} [settings.hoverColor="#00ff00ff"] - The css value of a color to be used if the pointer hovers over the button
|
|
25
|
+
* @param {string} [settings.borderStrokeColor="#000000"] - The css value of a color to be used to draw the border
|
|
26
|
+
* @param {string} [settings.fillStyle] - The css value of a tint color to be used to tint the BitmapText
|
|
27
|
+
* @param {string} [settings.textAlign="center"] - horizontal text alignment
|
|
28
|
+
* @param {string} [settings.textBaseline="middle"] - the text baseline
|
|
28
29
|
* @param {number} [settings.borderWidth] - Width of the button
|
|
29
30
|
* @param {number} [settings.borderHeight] - Height of the button
|
|
30
31
|
* @example
|
|
31
32
|
* // Create a new Button
|
|
32
|
-
* class PlayButton extends
|
|
33
|
+
* class PlayButton extends UITextButton {
|
|
33
34
|
* constructor(x,y) {
|
|
34
35
|
* super(x,y, {
|
|
35
36
|
* font: 'my-font',
|
|
@@ -45,74 +46,93 @@ import UIBaseElement from "./uibaseelement.js";
|
|
|
45
46
|
* }
|
|
46
47
|
* }
|
|
47
48
|
*
|
|
48
|
-
*
|
|
49
|
+
* world.addChild(new PlayButton(15,200));
|
|
49
50
|
*/
|
|
50
51
|
constructor(x, y, settings) {
|
|
51
52
|
super(x, y);
|
|
52
|
-
settings.font = settings.font || "24Outline";
|
|
53
|
-
settings.size = settings.size || 1;
|
|
54
|
-
settings.text = settings.text || "<Click Me>";
|
|
55
|
-
settings.bindKey = settings.bindKey || -1;
|
|
56
|
-
settings.backgroundColor = settings.backgroundColor || "#00aa00";
|
|
57
|
-
settings.hoverColor = settings.hoverColor || "#00ff00";
|
|
58
|
-
settings.borderStrokeColor = settings.borderStrokeColor || "#000000";
|
|
59
|
-
settings.fillStyle = settings.fillStyle || "#ffffff";
|
|
60
|
-
settings.lineWidth = settings.lineWidth || 1;
|
|
61
|
-
settings.anchorPoint = settings.anchorPoint || new Vector2d(0, 0);
|
|
62
|
-
|
|
63
|
-
let font = new BitmapText(x, y, settings);
|
|
64
|
-
let dimensions = font.measureText();
|
|
65
|
-
settings.borderWidth = settings.borderWidth || dimensions.width + 16;
|
|
66
|
-
settings.borderHeight = settings.borderHeight || dimensions.height + 16;
|
|
67
|
-
|
|
68
|
-
let border = new RoundRect(
|
|
69
|
-
x,
|
|
70
|
-
y,
|
|
71
|
-
settings.borderWidth,
|
|
72
|
-
settings.borderHeight
|
|
73
|
-
);
|
|
74
|
-
super.setShape(
|
|
75
|
-
x,
|
|
76
|
-
y,
|
|
77
|
-
border.getBounds().width,
|
|
78
|
-
border.getBounds().height
|
|
79
|
-
);
|
|
80
53
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
this.
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
54
|
+
/**
|
|
55
|
+
* The key to bind the action to
|
|
56
|
+
* @type {string}
|
|
57
|
+
*/
|
|
58
|
+
this.bindKey = settings.bindKey || -1;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* The css value of a background color
|
|
62
|
+
* @type {string}
|
|
63
|
+
*/
|
|
64
|
+
this.backgroundColor = settings.backgroundColor || "#00aa0080";
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* The css value of a color to be used if the pointer hovers over the button
|
|
68
|
+
* @type {string}
|
|
69
|
+
*/
|
|
70
|
+
this.hoverColor = settings.hoverColor || "#00ff00ff";
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* The css value of a color to be used to draw the border
|
|
74
|
+
* @type {string}
|
|
75
|
+
*/
|
|
76
|
+
this.borderStrokeColor = settings.borderStrokeColor || "#000000";
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Set the default text alignment (or justification),<br>
|
|
80
|
+
* possible values are "left", "right", and "center".
|
|
81
|
+
* @public
|
|
82
|
+
* @type {string}
|
|
83
|
+
* @default "center"
|
|
84
|
+
*/
|
|
85
|
+
this.textAlign = settings.textAlign = settings.textAlign || "center";
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Set the text baseline (e.g. the Y-coordinate for the draw operation), <br>
|
|
89
|
+
* possible values are "top", "hanging, "middle, "alphabetic, "ideographic, "bottom"<br>
|
|
90
|
+
* @public
|
|
91
|
+
* @type {string}
|
|
92
|
+
* @default "middle"
|
|
93
|
+
*/
|
|
94
|
+
this.textBaseline = settings.textBaseline = settings.textBaseline || "middle";
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* the bitmapText used by the UITextButton class
|
|
98
|
+
* @type {BitmapText}
|
|
99
|
+
*/
|
|
100
|
+
this.bitmapText = new BitmapText(0, 0, settings);
|
|
101
|
+
|
|
102
|
+
// "detect" the button size
|
|
103
|
+
this.dimensions = this.bitmapText.measureText();
|
|
104
|
+
settings.borderWidth = settings.borderWidth || this.dimensions.width + 16;
|
|
105
|
+
settings.borderHeight = settings.borderHeight || this.dimensions.height + 16;
|
|
106
|
+
|
|
107
|
+
// create the round rect button
|
|
108
|
+
this.border = new RoundRect(x, y, settings.borderWidth, settings.borderHeight);
|
|
109
|
+
|
|
110
|
+
// resize the container accordingly
|
|
111
|
+
this.resize(
|
|
112
|
+
this.border.getBounds().width,
|
|
113
|
+
this.border.getBounds().height
|
|
92
114
|
);
|
|
115
|
+
|
|
116
|
+
// adjust size position
|
|
117
|
+
this.bitmapText.pos.set(this.width / 2, this.height / 2);
|
|
118
|
+
|
|
119
|
+
// add bitmapText to the UI container
|
|
120
|
+
this.addChild(this.bitmapText);
|
|
93
121
|
}
|
|
94
122
|
|
|
95
123
|
draw(renderer) {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
renderer.setColor(this.settings.backgroundColor);
|
|
124
|
+
if (this.hover === true) {
|
|
125
|
+
renderer.setColor(this.hoverColor);
|
|
99
126
|
} else {
|
|
100
|
-
renderer.setColor(this.
|
|
127
|
+
renderer.setColor(this.backgroundColor);
|
|
101
128
|
}
|
|
102
|
-
|
|
103
129
|
renderer.fill(this.border);
|
|
104
|
-
renderer.
|
|
105
|
-
renderer.setColor(this.settings.borderStrokeColor);
|
|
130
|
+
renderer.setColor(this.borderStrokeColor);
|
|
106
131
|
renderer.stroke(this.border);
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
renderer,
|
|
112
|
-
this.settings.text,
|
|
113
|
-
this.font.pos.x,
|
|
114
|
-
this.font.pos.y
|
|
115
|
-
);
|
|
132
|
+
this.bitmapText.preDraw(renderer);
|
|
133
|
+
this.bitmapText.draw(renderer);
|
|
134
|
+
this.bitmapText.postDraw(renderer);
|
|
135
|
+
super.draw(renderer);
|
|
116
136
|
}
|
|
117
137
|
}
|
|
118
138
|
|
package/src/state/stage.js
CHANGED
|
@@ -4,10 +4,10 @@ import Camera2d from "./../camera/camera2d.js";
|
|
|
4
4
|
import Color from "./../math/color.js";
|
|
5
5
|
|
|
6
6
|
// a default camera instance to use across all stages
|
|
7
|
-
|
|
7
|
+
let default_camera;
|
|
8
8
|
|
|
9
9
|
// default stage settings
|
|
10
|
-
|
|
10
|
+
let default_settings = {
|
|
11
11
|
cameras : []
|
|
12
12
|
};
|
|
13
13
|
|
|
@@ -49,7 +49,7 @@ var default_settings = {
|
|
|
49
49
|
* @see Stage.ambientLight
|
|
50
50
|
* @example
|
|
51
51
|
* // create a white spot light
|
|
52
|
-
*
|
|
52
|
+
* let whiteLight = new me.Light2d(0, 0, 140, "#fff", 0.7);
|
|
53
53
|
* // and add the light to this current stage
|
|
54
54
|
* this.lights.set("whiteLight", whiteLight);
|
|
55
55
|
* // set a dark ambient light
|
|
@@ -96,8 +96,8 @@ var default_settings = {
|
|
|
96
96
|
// empty or no default camera
|
|
97
97
|
if (this.cameras.has("default") === false) {
|
|
98
98
|
if (typeof default_camera === "undefined") {
|
|
99
|
-
|
|
100
|
-
|
|
99
|
+
let width = renderer.getWidth();
|
|
100
|
+
let height = renderer.getHeight();
|
|
101
101
|
// new default camera instance
|
|
102
102
|
default_camera = new Camera2d(0, 0, width, height);
|
|
103
103
|
}
|
|
@@ -121,7 +121,7 @@ var default_settings = {
|
|
|
121
121
|
*/
|
|
122
122
|
update(dt) {
|
|
123
123
|
// update all objects (and pass the elapsed time since last frame)
|
|
124
|
-
|
|
124
|
+
let isDirty = game.world.update(dt);
|
|
125
125
|
|
|
126
126
|
// update the camera/viewport
|
|
127
127
|
// iterate through all cameras
|
package/src/state/state.js
CHANGED
|
@@ -8,32 +8,32 @@ import DefaultLoadingScreen from "./../loader/loadingscreen.js";
|
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
// current state
|
|
11
|
-
|
|
11
|
+
let _state = -1;
|
|
12
12
|
|
|
13
13
|
// requestAnimeFrame Id
|
|
14
|
-
|
|
14
|
+
let _animFrameId = -1;
|
|
15
15
|
|
|
16
16
|
// whether the game state is "paused"
|
|
17
|
-
|
|
17
|
+
let _isPaused = false;
|
|
18
18
|
|
|
19
19
|
// list of stages
|
|
20
|
-
|
|
20
|
+
let _stages = {};
|
|
21
21
|
|
|
22
22
|
// fading transition parameters between screen
|
|
23
|
-
|
|
23
|
+
let _fade = {
|
|
24
24
|
color : "",
|
|
25
25
|
duration : 0
|
|
26
26
|
};
|
|
27
27
|
|
|
28
28
|
// callback when state switch is done
|
|
29
29
|
/** @ignore */
|
|
30
|
-
|
|
30
|
+
let _onSwitchComplete = null;
|
|
31
31
|
|
|
32
32
|
// just to keep track of possible extra arguments
|
|
33
|
-
|
|
33
|
+
let _extraArgs = null;
|
|
34
34
|
|
|
35
35
|
// store the elapsed time during pause/stop period
|
|
36
|
-
|
|
36
|
+
let _pauseTime = 0;
|
|
37
37
|
|
|
38
38
|
/**
|
|
39
39
|
* @ignore
|
|
@@ -72,7 +72,7 @@ function _pauseRunLoop() {
|
|
|
72
72
|
* @ignore
|
|
73
73
|
*/
|
|
74
74
|
function _renderFrame(time) {
|
|
75
|
-
|
|
75
|
+
let stage = _stages[_state].stage;
|
|
76
76
|
// update all game objects
|
|
77
77
|
game.update(time, stage);
|
|
78
78
|
// render all game objects
|
|
@@ -195,7 +195,7 @@ event.on(event.BOOT, () => {
|
|
|
195
195
|
* a State Manager (state machine)
|
|
196
196
|
* @namespace state
|
|
197
197
|
*/
|
|
198
|
-
|
|
198
|
+
let state = {
|
|
199
199
|
|
|
200
200
|
/**
|
|
201
201
|
* default state ID for Loading Stage
|
|
@@ -284,10 +284,10 @@ var state = {
|
|
|
284
284
|
* @name USER
|
|
285
285
|
* @memberof state
|
|
286
286
|
* @example
|
|
287
|
-
*
|
|
288
|
-
*
|
|
289
|
-
*
|
|
290
|
-
*
|
|
287
|
+
* let STATE_INFO = me.state.USER + 0;
|
|
288
|
+
* let STATE_WARN = me.state.USER + 1;
|
|
289
|
+
* let STATE_ERROR = me.state.USER + 2;
|
|
290
|
+
* let STATE_CUTSCENE = me.state.USER + 3;
|
|
291
291
|
*/
|
|
292
292
|
USER : 100,
|
|
293
293
|
|
package/src/system/device.js
CHANGED
|
@@ -392,7 +392,7 @@ export let stopOnBlur = false;
|
|
|
392
392
|
* @param {Function} fn - the function to be executed
|
|
393
393
|
* @example
|
|
394
394
|
* // small game skeleton
|
|
395
|
-
*
|
|
395
|
+
* let game = {
|
|
396
396
|
* // called by the me.device.onReady function
|
|
397
397
|
* onload = function () {
|
|
398
398
|
* // init video
|
package/src/system/event.js
CHANGED
package/src/system/pooling.js
CHANGED
|
@@ -58,11 +58,11 @@ class ObjectPool {
|
|
|
58
58
|
* me.pool.register("enemy", EnemyEntity, true);
|
|
59
59
|
* // ...
|
|
60
60
|
* // when we need to manually create a new bullet:
|
|
61
|
-
*
|
|
61
|
+
* let bullet = me.pool.pull("bullet", x, y, direction);
|
|
62
62
|
* // ...
|
|
63
63
|
* // params aren't a fixed number
|
|
64
64
|
* // when we need new enemy we can add more params, that the object construct requires:
|
|
65
|
-
*
|
|
65
|
+
* let enemy = me.pool.pull("enemy", x, y, direction, speed, power, life);
|
|
66
66
|
* // ...
|
|
67
67
|
* // when we want to destroy existing object, the remove
|
|
68
68
|
* // function will ensure the object can then be reallocated later
|
|
@@ -70,9 +70,9 @@ class ObjectPool {
|
|
|
70
70
|
* me.game.world.removeChild(bullet);
|
|
71
71
|
*/
|
|
72
72
|
pull(name, ...args) {
|
|
73
|
-
|
|
73
|
+
let className = this.objectClass[name];
|
|
74
74
|
if (className) {
|
|
75
|
-
|
|
75
|
+
let proto = className["class"],
|
|
76
76
|
poolArray = className.pool,
|
|
77
77
|
obj;
|
|
78
78
|
|
|
@@ -98,7 +98,7 @@ class ObjectPool {
|
|
|
98
98
|
* note: this will trigger the garbage collector
|
|
99
99
|
*/
|
|
100
100
|
purge() {
|
|
101
|
-
for (
|
|
101
|
+
for (let className in this.objectClass) {
|
|
102
102
|
if (this.objectClass[className]) {
|
|
103
103
|
this.objectClass[className].pool = [];
|
|
104
104
|
}
|
|
@@ -153,7 +153,7 @@ class ObjectPool {
|
|
|
153
153
|
* }
|
|
154
154
|
*/
|
|
155
155
|
poolable(obj) {
|
|
156
|
-
|
|
156
|
+
let className = obj.className;
|
|
157
157
|
return (typeof className !== "undefined") &&
|
|
158
158
|
(typeof obj.onResetEvent === "function") &&
|
|
159
159
|
(className in this.objectClass) &&
|
|
@@ -170,7 +170,7 @@ class ObjectPool {
|
|
|
170
170
|
}
|
|
171
171
|
}
|
|
172
172
|
|
|
173
|
-
|
|
173
|
+
let pool = new ObjectPool();
|
|
174
174
|
|
|
175
175
|
/**
|
|
176
176
|
* a default global ObjectPool instance
|
|
@@ -181,7 +181,7 @@ var pool = new ObjectPool();
|
|
|
181
181
|
* pool.register("bullet", BulletEntity, true);
|
|
182
182
|
* // ...
|
|
183
183
|
* // when we need to manually create a new bullet:
|
|
184
|
-
*
|
|
184
|
+
* let bullet = pool.pull("bullet", x, y, direction, velocity);
|
|
185
185
|
* // ...
|
|
186
186
|
* // when we want to destroy existing object, the remove
|
|
187
187
|
* // function will ensure the object can then be reallocated later
|
package/src/system/save.js
CHANGED
|
@@ -32,7 +32,7 @@ import * as event from "./event.js";
|
|
|
32
32
|
*/
|
|
33
33
|
|
|
34
34
|
// Variable to hold the object data
|
|
35
|
-
|
|
35
|
+
let data = {};
|
|
36
36
|
|
|
37
37
|
let hasLocalStorage = false;
|
|
38
38
|
|
|
@@ -57,10 +57,10 @@ function isReserved(key) {
|
|
|
57
57
|
event.on(event.BOOT, () => {
|
|
58
58
|
// Load previous data if local Storage is supported
|
|
59
59
|
if (hasLocalStorage === true) {
|
|
60
|
-
|
|
60
|
+
let me_save_content = globalThis.localStorage.getItem("me.save");
|
|
61
61
|
|
|
62
62
|
if (typeof me_save_content === "string" && me_save_content.length > 0) {
|
|
63
|
-
|
|
63
|
+
let keys = JSON.parse(me_save_content) || [];
|
|
64
64
|
keys.forEach((key) => {
|
|
65
65
|
data[key] = JSON.parse(globalThis.localStorage.getItem("me.save." + key));
|
|
66
66
|
});
|
|
@@ -68,7 +68,7 @@ event.on(event.BOOT, () => {
|
|
|
68
68
|
}
|
|
69
69
|
});
|
|
70
70
|
|
|
71
|
-
|
|
71
|
+
let save = {
|
|
72
72
|
|
|
73
73
|
/**
|
|
74
74
|
* Add new keys to localStorage and set them to the given default values if they do not exist
|
|
@@ -82,7 +82,7 @@ var save = {
|
|
|
82
82
|
* me.save.score = 1000;
|
|
83
83
|
*/
|
|
84
84
|
add(props) {
|
|
85
|
-
|
|
85
|
+
let obj = save;
|
|
86
86
|
|
|
87
87
|
Object.keys(props).forEach((key) => {
|
|
88
88
|
if (isReserved(key)) {
|
package/src/system/timer.js
CHANGED
|
@@ -71,7 +71,7 @@ class Timer {
|
|
|
71
71
|
this.reset();
|
|
72
72
|
this.now = this.last = 0;
|
|
73
73
|
// register to the game before update event
|
|
74
|
-
event.on(event.GAME_BEFORE_UPDATE, this.update
|
|
74
|
+
event.on(event.GAME_BEFORE_UPDATE, (time) => this.update(time));
|
|
75
75
|
});
|
|
76
76
|
|
|
77
77
|
// reset timer
|
|
@@ -109,7 +109,7 @@ class Timer {
|
|
|
109
109
|
* @param {number} delay - the number of milliseconds (thousandths of a second) that the function call should be delayed by.
|
|
110
110
|
* @param {boolean} [pauseable=true] - respects the pause state of the engine.
|
|
111
111
|
* @param {...*} args - optional parameters which are passed through to the function specified by fn once the timer expires.
|
|
112
|
-
* @returns {number}
|
|
112
|
+
* @returns {number} a positive integer value which identifies the timer created by the call to setTimeout(), which can be used later with me.timer.clearTimeout().
|
|
113
113
|
* @example
|
|
114
114
|
* // set a timer to call "myFunction" after 1000ms
|
|
115
115
|
* me.timer.setTimeout(myFunction, 1000);
|
|
@@ -135,7 +135,7 @@ class Timer {
|
|
|
135
135
|
* @param {number} delay - the number of milliseconds (thousandths of a second) on how often to execute the function
|
|
136
136
|
* @param {boolean} [pauseable=true] - respects the pause state of the engine.
|
|
137
137
|
* @param {...*} args - optional parameters which are passed through to the function specified by fn once the timer expires.
|
|
138
|
-
* @returns {number}
|
|
138
|
+
* @returns {number} a numeric, non-zero value which identifies the timer created by the call to setInterval(), which can be used later with me.timer.clearInterval().
|
|
139
139
|
* @example
|
|
140
140
|
* // set a timer to call "myFunction" every 1000ms
|
|
141
141
|
* me.timer.setInterval(myFunction, 1000);
|
|
@@ -156,19 +156,23 @@ class Timer {
|
|
|
156
156
|
}
|
|
157
157
|
|
|
158
158
|
/**
|
|
159
|
-
*
|
|
160
|
-
* @param {number} timeoutID - ID of the timeout to be
|
|
159
|
+
* Cancels a timeout previously established by calling setTimeout().
|
|
160
|
+
* @param {number} timeoutID - ID of the timeout to be cancelled
|
|
161
161
|
*/
|
|
162
162
|
clearTimeout(timeoutID) {
|
|
163
|
-
|
|
163
|
+
if (timeoutID > 0) {
|
|
164
|
+
utils.function.defer(this.clearTimer.bind(this), this, timeoutID);
|
|
165
|
+
}
|
|
164
166
|
}
|
|
165
167
|
|
|
166
168
|
/**
|
|
167
|
-
*
|
|
169
|
+
* cancels the timed, repeating action which was previously established by a call to setInterval().
|
|
168
170
|
* @param {number} intervalID - ID of the interval to be cleared
|
|
169
171
|
*/
|
|
170
172
|
clearInterval(intervalID) {
|
|
171
|
-
|
|
173
|
+
if (intervalID > 0) {
|
|
174
|
+
utils.function.defer(this.clearTimer.bind(this), this, intervalID);
|
|
175
|
+
}
|
|
172
176
|
}
|
|
173
177
|
|
|
174
178
|
/**
|
|
@@ -227,7 +231,7 @@ class Timer {
|
|
|
227
231
|
* @ignore
|
|
228
232
|
*/
|
|
229
233
|
clearTimer(timerId) {
|
|
230
|
-
for (
|
|
234
|
+
for (let i = 0, len = this.timers.length; i < len; i++) {
|
|
231
235
|
if (this.timers[i].timerId === timerId) {
|
|
232
236
|
this.timers.splice(i, 1);
|
|
233
237
|
break;
|
|
@@ -241,8 +245,8 @@ class Timer {
|
|
|
241
245
|
* @ignore
|
|
242
246
|
*/
|
|
243
247
|
updateTimers() {
|
|
244
|
-
for (
|
|
245
|
-
|
|
248
|
+
for (let i = 0, len = this.timers.length; i < len; i++) {
|
|
249
|
+
let _timer = this.timers[i];
|
|
246
250
|
if (!(_timer.pauseable && state.isPaused())) {
|
|
247
251
|
_timer.elapsed += this.delta;
|
|
248
252
|
}
|
package/src/text/bitmaptext.js
CHANGED
|
@@ -32,7 +32,7 @@ import TextMetrics from "./textmetrics.js";
|
|
|
32
32
|
* { name: "arial", type: "image" src: "data/font/arial.png" },
|
|
33
33
|
* ])
|
|
34
34
|
* // Then create an instance of your bitmap font:
|
|
35
|
-
*
|
|
35
|
+
* let myFont = new me.BitmapText(x, y, {font:"arial", text:"Hello"});
|
|
36
36
|
* // two possibilities for using "myFont"
|
|
37
37
|
* // either call the draw function from your Renderable draw function
|
|
38
38
|
* myFont.draw(renderer, "Hello!", 0, 0);
|
|
@@ -187,12 +187,12 @@ import TextMetrics from "./textmetrics.js";
|
|
|
187
187
|
* @returns {Bounds} this Bitmap Text bounding box Rectangle object
|
|
188
188
|
*/
|
|
189
189
|
updateBounds(absolute = true) {
|
|
190
|
-
|
|
190
|
+
let bounds = this.getBounds();
|
|
191
191
|
|
|
192
192
|
bounds.clear();
|
|
193
193
|
|
|
194
194
|
if (typeof this.metrics !== "undefined") {
|
|
195
|
-
|
|
195
|
+
let ax, ay;
|
|
196
196
|
|
|
197
197
|
bounds.addBounds(this.metrics.measureText(this._text));
|
|
198
198
|
|
|
@@ -291,7 +291,7 @@ import TextMetrics from "./textmetrics.js";
|
|
|
291
291
|
*/
|
|
292
292
|
draw(renderer, text, x, y) {
|
|
293
293
|
// save the previous global alpha value
|
|
294
|
-
|
|
294
|
+
let _alpha = renderer.globalAlpha();
|
|
295
295
|
|
|
296
296
|
// allows to provide backward compatibility when
|
|
297
297
|
// adding Bitmap Font to an object container
|
|
@@ -305,15 +305,15 @@ import TextMetrics from "./textmetrics.js";
|
|
|
305
305
|
y = this.pos.y;
|
|
306
306
|
}
|
|
307
307
|
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
308
|
+
let lX = x;
|
|
309
|
+
let stringHeight = this.metrics.lineHeight();
|
|
310
|
+
let maxWidth = 0;
|
|
311
311
|
|
|
312
|
-
for (
|
|
312
|
+
for (let i = 0; i < this._text.length; i++) {
|
|
313
313
|
x = lX;
|
|
314
|
-
|
|
314
|
+
let string = this._text[i].trimEnd();
|
|
315
315
|
// adjust x pos based on alignment value
|
|
316
|
-
|
|
316
|
+
let stringWidth = this.metrics.lineWidth(string);
|
|
317
317
|
switch (this.textAlign) {
|
|
318
318
|
case "right":
|
|
319
319
|
x -= stringWidth;
|
|
@@ -355,18 +355,18 @@ import TextMetrics from "./textmetrics.js";
|
|
|
355
355
|
}
|
|
356
356
|
|
|
357
357
|
// draw the string
|
|
358
|
-
|
|
359
|
-
for (
|
|
358
|
+
let lastGlyph = null;
|
|
359
|
+
for (let c = 0, len = string.length; c < len; c++) {
|
|
360
360
|
// calculate the char index
|
|
361
|
-
|
|
362
|
-
|
|
361
|
+
let ch = string.charCodeAt(c);
|
|
362
|
+
let glyph = this.fontData.glyphs[ch];
|
|
363
363
|
|
|
364
364
|
if (typeof glyph !== "undefined") {
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
365
|
+
let glyphWidth = glyph.width;
|
|
366
|
+
let glyphHeight = glyph.height;
|
|
367
|
+
let kerning = (lastGlyph && lastGlyph.kerning) ? lastGlyph.getKerning(ch) : 0;
|
|
368
|
+
let scaleX = this.fontScale.x;
|
|
369
|
+
let scaleY = this.fontScale.y;
|
|
370
370
|
|
|
371
371
|
// draw it
|
|
372
372
|
if (glyphWidth !== 0 && glyphHeight !== 0) {
|