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.
Files changed (285) hide show
  1. package/README.md +4 -4
  2. package/dist/melonjs.mjs/_virtual/_commonjsHelpers.js +1 -1
  3. package/dist/melonjs.mjs/_virtual/arraymultimap.js +1 -1
  4. package/dist/melonjs.mjs/_virtual/earcut.js +1 -1
  5. package/dist/melonjs.mjs/_virtual/howler.js +1 -1
  6. package/dist/melonjs.mjs/_virtual/index.js +7 -3
  7. package/dist/melonjs.mjs/_virtual/index2.js +1 -1
  8. package/dist/melonjs.mjs/_virtual/multimap.js +1 -1
  9. package/dist/melonjs.mjs/_virtual/setmultimap.js +1 -1
  10. package/dist/melonjs.mjs/application/application.js +27 -17
  11. package/dist/melonjs.mjs/application/header.js +6 -5
  12. package/dist/melonjs.mjs/application/resize.js +20 -20
  13. package/dist/melonjs.mjs/application/settings.js +1 -1
  14. package/dist/melonjs.mjs/audio/audio.js +17 -17
  15. package/dist/melonjs.mjs/camera/camera2d.js +10 -10
  16. package/dist/melonjs.mjs/const.js +1 -1
  17. package/dist/melonjs.mjs/entity/entity.js +4 -4
  18. package/dist/melonjs.mjs/geometries/ellipse.js +6 -6
  19. package/dist/melonjs.mjs/geometries/line.js +9 -9
  20. package/dist/melonjs.mjs/geometries/path2d.js +53 -53
  21. package/dist/melonjs.mjs/geometries/point.js +2 -2
  22. package/dist/melonjs.mjs/geometries/poly.js +29 -29
  23. package/dist/melonjs.mjs/geometries/rectangle.js +8 -8
  24. package/dist/melonjs.mjs/geometries/roundrect.js +6 -6
  25. package/dist/melonjs.mjs/index.js +5 -5
  26. package/dist/melonjs.mjs/input/gamepad.js +30 -30
  27. package/dist/melonjs.mjs/input/input.js +2 -2
  28. package/dist/melonjs.mjs/input/keyboard.js +15 -15
  29. package/dist/melonjs.mjs/input/pointer.js +2 -2
  30. package/dist/melonjs.mjs/input/pointerevent.js +58 -58
  31. package/dist/melonjs.mjs/lang/console.js +3 -3
  32. package/dist/melonjs.mjs/lang/deprecated.js +2 -2
  33. package/dist/melonjs.mjs/level/level.js +9 -9
  34. package/dist/melonjs.mjs/level/tiled/TMXGroup.js +3 -3
  35. package/dist/melonjs.mjs/level/tiled/TMXLayer.js +31 -31
  36. package/dist/melonjs.mjs/level/tiled/TMXObject.js +8 -8
  37. package/dist/melonjs.mjs/level/tiled/TMXTile.js +8 -8
  38. package/dist/melonjs.mjs/level/tiled/TMXTileMap.js +19 -19
  39. package/dist/melonjs.mjs/level/tiled/TMXTileset.js +15 -15
  40. package/dist/melonjs.mjs/level/tiled/TMXTilesetGroup.js +3 -3
  41. package/dist/melonjs.mjs/level/tiled/TMXUtils.js +46 -41
  42. package/dist/melonjs.mjs/level/tiled/constants.js +1 -1
  43. package/dist/melonjs.mjs/level/tiled/renderer/TMXHexagonalRenderer.js +30 -30
  44. package/dist/melonjs.mjs/level/tiled/renderer/TMXIsometricRenderer.js +21 -21
  45. package/dist/melonjs.mjs/level/tiled/renderer/TMXOrthogonalRenderer.js +10 -10
  46. package/dist/melonjs.mjs/level/tiled/renderer/TMXRenderer.js +2 -2
  47. package/dist/melonjs.mjs/level/tiled/renderer/TMXStaggeredRenderer.js +6 -6
  48. package/dist/melonjs.mjs/level/tiled/renderer/autodetect.js +1 -1
  49. package/dist/melonjs.mjs/loader/cache.js +1 -1
  50. package/dist/melonjs.mjs/loader/loader.js +7 -7
  51. package/dist/melonjs.mjs/loader/loadingscreen.js +2 -2
  52. package/dist/melonjs.mjs/loader/melonjs_logo.png.js +1 -1
  53. package/dist/melonjs.mjs/loader/parser.js +13 -13
  54. package/dist/melonjs.mjs/loader/settings.js +3 -3
  55. package/dist/melonjs.mjs/math/color.js +21 -21
  56. package/dist/melonjs.mjs/math/math.js +2 -2
  57. package/dist/melonjs.mjs/math/matrix2.js +22 -22
  58. package/dist/melonjs.mjs/math/matrix3.js +52 -52
  59. package/dist/melonjs.mjs/math/observable_vector2.js +12 -12
  60. package/dist/melonjs.mjs/math/observable_vector3.js +22 -22
  61. package/dist/melonjs.mjs/math/vector2.js +11 -11
  62. package/dist/melonjs.mjs/math/vector3.js +21 -21
  63. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/esm/arraymultimap.js +45 -0
  64. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/esm/multimap.js +130 -0
  65. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/arraymultimap.js +1 -1
  66. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/index.js +1 -1
  67. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/multimap.js +1 -1
  68. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/setmultimap.js +1 -1
  69. package/dist/melonjs.mjs/node_modules/earcut/src/earcut.js +1 -1
  70. package/dist/melonjs.mjs/node_modules/eventemitter3/index.js +2 -2
  71. package/dist/melonjs.mjs/node_modules/eventemitter3/index2.js +1 -1
  72. package/dist/melonjs.mjs/node_modules/howler/dist/howler.js +1 -1
  73. package/dist/melonjs.mjs/particles/emitter.js +5 -5
  74. package/dist/melonjs.mjs/particles/particle.js +8 -8
  75. package/dist/melonjs.mjs/particles/settings.js +3 -3
  76. package/dist/melonjs.mjs/physics/body.js +17 -17
  77. package/dist/melonjs.mjs/physics/bounds.js +12 -12
  78. package/dist/melonjs.mjs/physics/collision.js +3 -3
  79. package/dist/melonjs.mjs/physics/detector.js +14 -14
  80. package/dist/melonjs.mjs/physics/quadtree.js +19 -19
  81. package/dist/melonjs.mjs/physics/response.js +1 -1
  82. package/dist/melonjs.mjs/physics/sat.js +60 -60
  83. package/dist/melonjs.mjs/physics/world.js +4 -4
  84. package/dist/melonjs.mjs/plugin/plugin.js +11 -11
  85. package/dist/melonjs.mjs/renderable/collectable.js +2 -2
  86. package/dist/melonjs.mjs/renderable/colorlayer.js +1 -1
  87. package/dist/melonjs.mjs/renderable/container.js +77 -59
  88. package/dist/melonjs.mjs/renderable/dragndrop.js +5 -5
  89. package/dist/melonjs.mjs/renderable/imagelayer.js +7 -6
  90. package/dist/melonjs.mjs/renderable/light2d.js +6 -6
  91. package/dist/melonjs.mjs/renderable/nineslicesprite.js +12 -12
  92. package/dist/melonjs.mjs/renderable/renderable.js +11 -11
  93. package/dist/melonjs.mjs/renderable/sprite.js +25 -25
  94. package/dist/melonjs.mjs/renderable/trigger.js +11 -9
  95. package/dist/melonjs.mjs/renderable/ui/uibaseelement.js +97 -27
  96. package/dist/melonjs.mjs/renderable/ui/uispriteelement.js +25 -25
  97. package/dist/melonjs.mjs/renderable/ui/uitextbutton.js +83 -63
  98. package/dist/melonjs.mjs/state/stage.js +7 -7
  99. package/dist/melonjs.mjs/state/state.js +15 -15
  100. package/dist/melonjs.mjs/system/device.js +2 -2
  101. package/dist/melonjs.mjs/system/dom.js +1 -1
  102. package/dist/melonjs.mjs/system/event.js +2 -2
  103. package/dist/melonjs.mjs/system/platform.js +1 -1
  104. package/dist/melonjs.mjs/system/pooling.js +9 -9
  105. package/dist/melonjs.mjs/system/save.js +6 -6
  106. package/dist/melonjs.mjs/system/timer.js +16 -12
  107. package/dist/melonjs.mjs/text/bitmaptext.js +20 -20
  108. package/dist/melonjs.mjs/text/bitmaptextdata.js +22 -22
  109. package/dist/melonjs.mjs/text/glyph.js +3 -3
  110. package/dist/melonjs.mjs/text/text.js +10 -9
  111. package/dist/melonjs.mjs/text/textmetrics.js +15 -15
  112. package/dist/melonjs.mjs/text/textstyle.js +1 -1
  113. package/dist/melonjs.mjs/tweens/easing.js +4 -4
  114. package/dist/melonjs.mjs/tweens/interpolation.js +8 -8
  115. package/dist/melonjs.mjs/tweens/tween.js +11 -11
  116. package/dist/melonjs.mjs/utils/agent.js +6 -6
  117. package/dist/melonjs.mjs/utils/array.js +4 -4
  118. package/dist/melonjs.mjs/utils/file.js +1 -1
  119. package/dist/melonjs.mjs/utils/function.js +5 -5
  120. package/dist/melonjs.mjs/utils/string.js +3 -3
  121. package/dist/melonjs.mjs/utils/utils.js +16 -16
  122. package/dist/melonjs.mjs/video/canvas/canvas_renderer.js +35 -109
  123. package/dist/melonjs.mjs/video/renderer.js +74 -7
  124. package/dist/melonjs.mjs/video/texture/atlas.js +37 -37
  125. package/dist/melonjs.mjs/video/texture/cache.js +9 -10
  126. package/dist/melonjs.mjs/video/texture/canvas_texture.js +63 -3
  127. package/dist/melonjs.mjs/video/utils/autodetect.js +1 -1
  128. package/dist/melonjs.mjs/video/video.js +2 -2
  129. package/dist/melonjs.mjs/video/webgl/buffer/vertex.js +3 -3
  130. package/dist/melonjs.mjs/video/webgl/compositors/compositor.js +5 -5
  131. package/dist/melonjs.mjs/video/webgl/compositors/primitive_compositor.js +5 -5
  132. package/dist/melonjs.mjs/video/webgl/compositors/quad_compositor.js +18 -15
  133. package/dist/melonjs.mjs/video/webgl/glshader.js +7 -7
  134. package/dist/melonjs.mjs/video/webgl/shaders/primitive.frag.js +1 -1
  135. package/dist/melonjs.mjs/video/webgl/shaders/primitive.vert.js +1 -1
  136. package/dist/melonjs.mjs/video/webgl/shaders/quad.frag.js +1 -1
  137. package/dist/melonjs.mjs/video/webgl/shaders/quad.vert.js +1 -1
  138. package/dist/melonjs.mjs/video/webgl/utils/attributes.js +2 -2
  139. package/dist/melonjs.mjs/video/webgl/utils/precision.js +1 -1
  140. package/dist/melonjs.mjs/video/webgl/utils/program.js +7 -7
  141. package/dist/melonjs.mjs/video/webgl/utils/string.js +1 -1
  142. package/dist/melonjs.mjs/video/webgl/utils/uniforms.js +4 -4
  143. package/dist/melonjs.mjs/video/webgl/webgl_renderer.js +55 -38
  144. package/dist/melonjs.module.js +1747 -1809
  145. package/dist/types/application/application.d.ts +11 -8
  146. package/dist/types/audio/audio.d.ts +3 -3
  147. package/dist/types/index.d.ts +4 -3
  148. package/dist/types/input/input.d.ts +1 -1
  149. package/dist/types/input/keyboard.d.ts +1 -1
  150. package/dist/types/input/pointerevent.d.ts +6 -6
  151. package/dist/types/level/level.d.ts +2 -2
  152. package/dist/types/level/tiled/TMXLayer.d.ts +4 -4
  153. package/dist/types/level/tiled/TMXTileMap.d.ts +2 -2
  154. package/dist/types/level/tiled/TMXUtils.d.ts +5 -4
  155. package/dist/types/loader/loader.d.ts +2 -2
  156. package/dist/types/loader/settings.d.ts +2 -2
  157. package/dist/types/particles/emitter.d.ts +1 -1
  158. package/dist/types/physics/collision.d.ts +1 -1
  159. package/dist/types/physics/detector.d.ts +1 -1
  160. package/dist/types/plugin/plugin.d.ts +2 -2
  161. package/dist/types/renderable/container.d.ts +21 -17
  162. package/dist/types/renderable/sprite.d.ts +11 -11
  163. package/dist/types/renderable/trigger.d.ts +1 -1
  164. package/dist/types/renderable/ui/uibaseelement.d.ts +28 -6
  165. package/dist/types/renderable/ui/uispriteelement.d.ts +12 -14
  166. package/dist/types/renderable/ui/uitextbutton.d.ts +52 -11
  167. package/dist/types/state/stage.d.ts +1 -1
  168. package/dist/types/system/device.d.ts +1 -1
  169. package/dist/types/system/pooling.d.ts +3 -3
  170. package/dist/types/system/timer.d.ts +5 -5
  171. package/dist/types/text/bitmaptext.d.ts +1 -1
  172. package/dist/types/text/text.d.ts +1 -1
  173. package/dist/types/utils/array.d.ts +2 -2
  174. package/dist/types/video/canvas/canvas_renderer.d.ts +8 -76
  175. package/dist/types/video/renderer.d.ts +48 -0
  176. package/dist/types/video/texture/atlas.d.ts +3 -3
  177. package/dist/types/video/texture/canvas_texture.d.ts +40 -0
  178. package/dist/types/video/webgl/glshader.d.ts +1 -1
  179. package/dist/types/video/webgl/webgl_renderer.d.ts +13 -9
  180. package/package.json +14 -14
  181. package/src/application/application.js +26 -16
  182. package/src/application/header.js +5 -4
  183. package/src/application/resize.js +19 -19
  184. package/src/audio/audio.js +16 -16
  185. package/src/camera/camera2d.js +9 -9
  186. package/src/entity/entity.js +3 -3
  187. package/src/geometries/ellipse.js +5 -5
  188. package/src/geometries/line.js +8 -8
  189. package/src/geometries/path2d.js +52 -52
  190. package/src/geometries/point.js +1 -1
  191. package/src/geometries/poly.js +28 -28
  192. package/src/geometries/rectangle.js +7 -7
  193. package/src/geometries/roundrect.js +5 -5
  194. package/src/index.js +3 -2
  195. package/src/input/gamepad.js +29 -29
  196. package/src/input/input.js +1 -1
  197. package/src/input/keyboard.js +14 -14
  198. package/src/input/pointer.js +1 -1
  199. package/src/input/pointerevent.js +52 -52
  200. package/src/lang/console.js +2 -2
  201. package/src/lang/deprecated.js +1 -1
  202. package/src/level/level.js +8 -8
  203. package/src/level/tiled/TMXGroup.js +2 -2
  204. package/src/level/tiled/TMXLayer.js +30 -30
  205. package/src/level/tiled/TMXObject.js +7 -7
  206. package/src/level/tiled/TMXTile.js +7 -7
  207. package/src/level/tiled/TMXTileMap.js +18 -18
  208. package/src/level/tiled/TMXTileset.js +14 -14
  209. package/src/level/tiled/TMXTilesetGroup.js +2 -2
  210. package/src/level/tiled/TMXUtils.js +45 -40
  211. package/src/level/tiled/renderer/TMXHexagonalRenderer.js +29 -29
  212. package/src/level/tiled/renderer/TMXIsometricRenderer.js +20 -20
  213. package/src/level/tiled/renderer/TMXOrthogonalRenderer.js +9 -9
  214. package/src/level/tiled/renderer/TMXRenderer.js +1 -1
  215. package/src/level/tiled/renderer/TMXStaggeredRenderer.js +5 -5
  216. package/src/loader/loader.js +6 -6
  217. package/src/loader/loadingscreen.js +1 -1
  218. package/src/loader/parser.js +12 -12
  219. package/src/loader/settings.js +2 -2
  220. package/src/math/color.js +20 -20
  221. package/src/math/math.js +1 -1
  222. package/src/math/matrix2.js +21 -21
  223. package/src/math/matrix3.js +51 -51
  224. package/src/math/observable_vector2.js +11 -11
  225. package/src/math/observable_vector3.js +21 -21
  226. package/src/math/vector2.js +10 -10
  227. package/src/math/vector3.js +20 -20
  228. package/src/particles/emitter.js +4 -4
  229. package/src/particles/particle.js +7 -7
  230. package/src/particles/settings.js +2 -2
  231. package/src/physics/body.js +16 -16
  232. package/src/physics/bounds.js +11 -11
  233. package/src/physics/collision.js +2 -2
  234. package/src/physics/detector.js +13 -13
  235. package/src/physics/quadtree.js +18 -18
  236. package/src/physics/sat.js +59 -59
  237. package/src/physics/world.js +3 -3
  238. package/src/plugin/plugin.js +8 -8
  239. package/src/renderable/collectable.js +1 -1
  240. package/src/renderable/container.js +76 -58
  241. package/src/renderable/dragndrop.js +4 -4
  242. package/src/renderable/imagelayer.js +6 -5
  243. package/src/renderable/light2d.js +5 -5
  244. package/src/renderable/nineslicesprite.js +11 -11
  245. package/src/renderable/renderable.js +10 -10
  246. package/src/renderable/sprite.js +24 -24
  247. package/src/renderable/trigger.js +10 -8
  248. package/src/renderable/ui/uibaseelement.js +96 -26
  249. package/src/renderable/ui/uispriteelement.js +24 -24
  250. package/src/renderable/ui/uitextbutton.js +85 -65
  251. package/src/state/stage.js +6 -6
  252. package/src/state/state.js +14 -14
  253. package/src/system/device.js +1 -1
  254. package/src/system/event.js +1 -1
  255. package/src/system/pooling.js +8 -8
  256. package/src/system/save.js +5 -5
  257. package/src/system/timer.js +15 -11
  258. package/src/text/bitmaptext.js +19 -19
  259. package/src/text/bitmaptextdata.js +21 -21
  260. package/src/text/glyph.js +2 -2
  261. package/src/text/text.js +9 -8
  262. package/src/text/textmetrics.js +14 -14
  263. package/src/tweens/easing.js +3 -3
  264. package/src/tweens/interpolation.js +7 -7
  265. package/src/tweens/tween.js +10 -10
  266. package/src/utils/agent.js +5 -5
  267. package/src/utils/array.js +3 -3
  268. package/src/utils/function.js +4 -4
  269. package/src/utils/string.js +2 -2
  270. package/src/utils/utils.js +15 -15
  271. package/src/video/canvas/canvas_renderer.js +34 -108
  272. package/src/video/renderer.js +72 -5
  273. package/src/video/texture/atlas.js +36 -36
  274. package/src/video/texture/cache.js +6 -6
  275. package/src/video/texture/canvas_texture.js +62 -2
  276. package/src/video/video.js +1 -1
  277. package/src/video/webgl/buffer/vertex.js +2 -2
  278. package/src/video/webgl/compositors/compositor.js +4 -4
  279. package/src/video/webgl/compositors/primitive_compositor.js +4 -4
  280. package/src/video/webgl/compositors/quad_compositor.js +17 -14
  281. package/src/video/webgl/glshader.js +6 -6
  282. package/src/video/webgl/utils/attributes.js +1 -1
  283. package/src/video/webgl/utils/program.js +6 -6
  284. package/src/video/webgl/utils/uniforms.js +3 -3
  285. 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 font (default: 1)
22
- * @param {string} [settings.text] - The text to display (default: 'click me')
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 text
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 BaseTextButton {
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
- * game.world.addChild(new PlayButton(15,200));
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
- // build up
82
- this.font = font;
83
- this.dimensions = dimensions;
84
- this.border = border;
85
- this.settings = settings;
86
-
87
- // adjust text position
88
- this.font.pos.set(
89
- Math.round((border.width - dimensions.width) / 2) + this.font.pos.x,
90
- Math.round((border.height - dimensions.height) / 2) +
91
- this.font.pos.y
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
- renderer.setGlobalAlpha(0.5);
97
- if (!this.hover) {
98
- renderer.setColor(this.settings.backgroundColor);
124
+ if (this.hover === true) {
125
+ renderer.setColor(this.hoverColor);
99
126
  } else {
100
- renderer.setColor(this.settings.hoverColor);
127
+ renderer.setColor(this.backgroundColor);
101
128
  }
102
-
103
129
  renderer.fill(this.border);
104
- renderer.setGlobalAlpha(1);
105
- renderer.setColor(this.settings.borderStrokeColor);
130
+ renderer.setColor(this.borderStrokeColor);
106
131
  renderer.stroke(this.border);
107
-
108
- // fix: supporting tint
109
- renderer.setTint(this.font.tint, this.font.getOpacity());
110
- this.font.draw(
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
 
@@ -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
- var default_camera;
7
+ let default_camera;
8
8
 
9
9
  // default stage settings
10
- var default_settings = {
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
- * var whiteLight = new me.Light2d(0, 0, 140, "#fff", 0.7);
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
- var width = renderer.getWidth();
100
- var height = renderer.getHeight();
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
- var isDirty = game.world.update(dt);
124
+ let isDirty = game.world.update(dt);
125
125
 
126
126
  // update the camera/viewport
127
127
  // iterate through all cameras
@@ -8,32 +8,32 @@ import DefaultLoadingScreen from "./../loader/loadingscreen.js";
8
8
 
9
9
 
10
10
  // current state
11
- var _state = -1;
11
+ let _state = -1;
12
12
 
13
13
  // requestAnimeFrame Id
14
- var _animFrameId = -1;
14
+ let _animFrameId = -1;
15
15
 
16
16
  // whether the game state is "paused"
17
- var _isPaused = false;
17
+ let _isPaused = false;
18
18
 
19
19
  // list of stages
20
- var _stages = {};
20
+ let _stages = {};
21
21
 
22
22
  // fading transition parameters between screen
23
- var _fade = {
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
- var _onSwitchComplete = null;
30
+ let _onSwitchComplete = null;
31
31
 
32
32
  // just to keep track of possible extra arguments
33
- var _extraArgs = null;
33
+ let _extraArgs = null;
34
34
 
35
35
  // store the elapsed time during pause/stop period
36
- var _pauseTime = 0;
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
- var stage = _stages[_state].stage;
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
- var state = {
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
- * var STATE_INFO = me.state.USER + 0;
288
- * var STATE_WARN = me.state.USER + 1;
289
- * var STATE_ERROR = me.state.USER + 2;
290
- * var STATE_CUTSCENE = me.state.USER + 3;
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
 
@@ -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
- * var game = {
395
+ * let game = {
396
396
  * // called by the me.device.onReady function
397
397
  * onload = function () {
398
398
  * // init video
@@ -6,7 +6,7 @@ import EventEmitter from "eventemitter3";
6
6
  */
7
7
 
8
8
  // internal instance of the event emiter
9
- var eventEmitter = new EventEmitter();
9
+ let eventEmitter = new EventEmitter();
10
10
 
11
11
  /**
12
12
  * event when the DOM is Ready is booting
@@ -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
- * var bullet = me.pool.pull("bullet", x, y, direction);
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
- * var enemy = me.pool.pull("enemy", x, y, direction, speed, power, life);
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
- var className = this.objectClass[name];
73
+ let className = this.objectClass[name];
74
74
  if (className) {
75
- var proto = className["class"],
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 (var className in this.objectClass) {
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
- var className = obj.className;
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
- var pool = new ObjectPool();
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
- * var bullet = pool.pull("bullet", x, y, direction, velocity);
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
@@ -32,7 +32,7 @@ import * as event from "./event.js";
32
32
  */
33
33
 
34
34
  // Variable to hold the object data
35
- var data = {};
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
- var me_save_content = globalThis.localStorage.getItem("me.save");
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
- var keys = JSON.parse(me_save_content) || [];
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
- var save = {
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
- var obj = save;
85
+ let obj = save;
86
86
 
87
87
  Object.keys(props).forEach((key) => {
88
88
  if (isReserved(key)) {
@@ -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.bind(this));
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} The numerical ID of the timer, which can be used later with me.timer.clearTimeout().
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} The numerical ID of the timer, which can be used later with me.timer.clearInterval().
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
- * Clears the delay set by me.timer.setTimeout().
160
- * @param {number} timeoutID - ID of the timeout to be cleared
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
- utils.function.defer(this.clearTimer.bind(this), this, timeoutID);
163
+ if (timeoutID > 0) {
164
+ utils.function.defer(this.clearTimer.bind(this), this, timeoutID);
165
+ }
164
166
  }
165
167
 
166
168
  /**
167
- * Clears the Interval set by me.timer.setInterval().
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
- utils.function.defer(this.clearTimer.bind(this), this, intervalID);
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 (var i = 0, len = this.timers.length; i < len; i++) {
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 (var i = 0, len = this.timers.length; i < len; i++) {
245
- var _timer = this.timers[i];
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
  }
@@ -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
- * var myFont = new me.BitmapText(x, y, {font:"arial", text:"Hello"});
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
- var bounds = this.getBounds();
190
+ let bounds = this.getBounds();
191
191
 
192
192
  bounds.clear();
193
193
 
194
194
  if (typeof this.metrics !== "undefined") {
195
- var ax, ay;
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
- var _alpha = renderer.globalAlpha();
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
- var lX = x;
309
- var stringHeight = this.metrics.lineHeight();
310
- var maxWidth = 0;
308
+ let lX = x;
309
+ let stringHeight = this.metrics.lineHeight();
310
+ let maxWidth = 0;
311
311
 
312
- for (var i = 0; i < this._text.length; i++) {
312
+ for (let i = 0; i < this._text.length; i++) {
313
313
  x = lX;
314
- var string = this._text[i].trimEnd();
314
+ let string = this._text[i].trimEnd();
315
315
  // adjust x pos based on alignment value
316
- var stringWidth = this.metrics.lineWidth(string);
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
- var lastGlyph = null;
359
- for (var c = 0, len = string.length; c < len; c++) {
358
+ let lastGlyph = null;
359
+ for (let c = 0, len = string.length; c < len; c++) {
360
360
  // calculate the char index
361
- var ch = string.charCodeAt(c);
362
- var glyph = this.fontData.glyphs[ch];
361
+ let ch = string.charCodeAt(c);
362
+ let glyph = this.fontData.glyphs[ch];
363
363
 
364
364
  if (typeof glyph !== "undefined") {
365
- var glyphWidth = glyph.width;
366
- var glyphHeight = glyph.height;
367
- var kerning = (lastGlyph && lastGlyph.kerning) ? lastGlyph.getKerning(ch) : 0;
368
- var scaleX = this.fontScale.x;
369
- var scaleY = this.fontScale.y;
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) {