melonjs 20.7.0 → 20.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (332) hide show
  1. package/README.md +7 -3
  2. package/build/application/application.d.ts +66 -8
  3. package/build/application/application.d.ts.map +1 -1
  4. package/build/application/defaultApplicationSettings.d.ts +6 -0
  5. package/build/application/defaultApplicationSettings.d.ts.map +1 -1
  6. package/build/application/header.d.ts.map +1 -1
  7. package/build/application/resize.d.ts +25 -0
  8. package/build/application/resize.d.ts.map +1 -1
  9. package/build/application/scaleMethods.d.ts +13 -3
  10. package/build/application/scaleMethods.d.ts.map +1 -1
  11. package/build/application/settings.d.ts +144 -5
  12. package/build/application/settings.d.ts.map +1 -1
  13. package/build/audio/audio.d.ts +29 -5
  14. package/build/audio/audio.d.ts.map +1 -1
  15. package/build/audio/autopause.d.ts +36 -0
  16. package/build/audio/autopause.d.ts.map +1 -0
  17. package/build/audio/backend/engine.d.ts +10 -1
  18. package/build/audio/backend/engine.d.ts.map +1 -1
  19. package/build/audio/backend/sound.d.ts +0 -1
  20. package/build/audio/backend/sound.d.ts.map +1 -1
  21. package/build/audio/backend/spatial.d.ts.map +1 -1
  22. package/build/audio/context.d.ts +35 -0
  23. package/build/audio/context.d.ts.map +1 -0
  24. package/build/audio/playback.d.ts.map +1 -1
  25. package/build/audio/procedural.d.ts.map +1 -1
  26. package/build/audio/spatial.d.ts +87 -0
  27. package/build/audio/spatial.d.ts.map +1 -0
  28. package/build/audio/state.d.ts +1 -0
  29. package/build/audio/state.d.ts.map +1 -1
  30. package/build/audio/types.d.ts +46 -6
  31. package/build/audio/types.d.ts.map +1 -1
  32. package/build/camera/camera2d.d.ts.map +1 -1
  33. package/build/camera/camera3d.d.ts +95 -8
  34. package/build/camera/camera3d.d.ts.map +1 -1
  35. package/build/camera/effects/fade_effect.d.ts.map +1 -1
  36. package/build/camera/effects/mask_effect.d.ts.map +1 -1
  37. package/build/camera/effects/shake_effect.d.ts.map +1 -1
  38. package/build/geometries/box3d.d.ts +25 -7
  39. package/build/geometries/box3d.d.ts.map +1 -1
  40. package/build/geometries/ellipse.d.ts +15 -1
  41. package/build/geometries/ellipse.d.ts.map +1 -1
  42. package/build/geometries/line.d.ts +1 -1
  43. package/build/geometries/line.d.ts.map +1 -1
  44. package/build/geometries/point.d.ts +1 -1
  45. package/build/geometries/point.d.ts.map +1 -1
  46. package/build/geometries/polygon.d.ts +15 -1
  47. package/build/geometries/polygon.d.ts.map +1 -1
  48. package/build/geometries/rectangle.d.ts +1 -1
  49. package/build/geometries/rectangle.d.ts.map +1 -1
  50. package/build/geometries/roundrect.d.ts +1 -1
  51. package/build/geometries/roundrect.d.ts.map +1 -1
  52. package/build/geometries/sphere.d.ts +36 -7
  53. package/build/geometries/sphere.d.ts.map +1 -1
  54. package/build/index.d.ts +16 -3
  55. package/build/index.d.ts.map +1 -1
  56. package/build/index.js +38172 -33633
  57. package/build/index.js.map +4 -4
  58. package/build/input/gamepad.d.ts +129 -3
  59. package/build/input/gamepad.d.ts.map +1 -1
  60. package/build/input/pointerevent.d.ts +8 -0
  61. package/build/input/pointerevent.d.ts.map +1 -1
  62. package/build/level/gltf/GLTFModel.d.ts +20 -33
  63. package/build/level/gltf/GLTFModel.d.ts.map +1 -1
  64. package/build/level/gltf/GLTFScene.d.ts +40 -1
  65. package/build/level/gltf/GLTFScene.d.ts.map +1 -1
  66. package/build/level/level.d.ts +35 -0
  67. package/build/level/level.d.ts.map +1 -1
  68. package/build/level/tiled/TMXLayer.d.ts +5 -2
  69. package/build/level/tiled/TMXLayer.d.ts.map +1 -1
  70. package/build/level/tiled/TMXObject.d.ts +0 -1
  71. package/build/level/tiled/TMXObjectFactory.d.ts +3 -2
  72. package/build/level/tiled/TMXObjectFactory.d.ts.map +1 -1
  73. package/build/level/tiled/TMXTile.d.ts +2 -1
  74. package/build/level/tiled/TMXTile.d.ts.map +1 -1
  75. package/build/level/tiled/TMXTileMap.d.ts +7 -4
  76. package/build/level/tiled/TMXTileMap.d.ts.map +1 -1
  77. package/build/level/tiled/TMXTileset.d.ts +1 -1
  78. package/build/level/tiled/TMXTileset.d.ts.map +1 -1
  79. package/build/level/tiled/TMXTilesetGroup.d.ts +5 -0
  80. package/build/level/tiled/TMXTilesetGroup.d.ts.map +1 -1
  81. package/build/level/tiled/factories/shape.d.ts +0 -1
  82. package/build/level/tiled/renderer/TMXHexagonalRenderer.d.ts +6 -5
  83. package/build/level/tiled/renderer/TMXHexagonalRenderer.d.ts.map +1 -1
  84. package/build/level/tiled/renderer/TMXIsometricRenderer.d.ts +5 -0
  85. package/build/level/tiled/renderer/TMXIsometricRenderer.d.ts.map +1 -1
  86. package/build/level/tiled/renderer/TMXObliqueRenderer.d.ts +5 -7
  87. package/build/level/tiled/renderer/TMXObliqueRenderer.d.ts.map +1 -1
  88. package/build/level/tiled/renderer/TMXOrthogonalRenderer.d.ts +5 -0
  89. package/build/level/tiled/renderer/TMXOrthogonalRenderer.d.ts.map +1 -1
  90. package/build/level/tiled/renderer/TMXRenderer.d.ts +19 -4
  91. package/build/level/tiled/renderer/TMXRenderer.d.ts.map +1 -1
  92. package/build/level/tiled/renderer/autodetect.d.ts +0 -4
  93. package/build/level/tiled/renderer/autodetect.d.ts.map +1 -1
  94. package/build/loader/cache.d.ts +220 -0
  95. package/build/loader/cache.d.ts.map +1 -1
  96. package/build/loader/loader.d.ts +20 -340
  97. package/build/loader/loader.d.ts.map +1 -1
  98. package/build/loader/loadingscreen.d.ts +1 -2
  99. package/build/loader/loadingscreen.d.ts.map +1 -1
  100. package/build/loader/parsers/gltf.d.ts +115 -0
  101. package/build/loader/parsers/gltf.d.ts.map +1 -1
  102. package/build/loader/parsers/shader.d.ts +0 -2
  103. package/build/math/color.d.ts +28 -5
  104. package/build/math/color.d.ts.map +1 -1
  105. package/build/math/matrix2d.d.ts +1 -1
  106. package/build/math/matrix2d.d.ts.map +1 -1
  107. package/build/math/matrix3d.d.ts +1 -1
  108. package/build/math/matrix3d.d.ts.map +1 -1
  109. package/build/math/observableVector2d.d.ts +14 -2
  110. package/build/math/observableVector2d.d.ts.map +1 -1
  111. package/build/math/observableVector3d.d.ts +15 -1
  112. package/build/math/observableVector3d.d.ts.map +1 -1
  113. package/build/math/vector2d.d.ts +31 -1
  114. package/build/math/vector2d.d.ts.map +1 -1
  115. package/build/math/vector3d.d.ts +38 -1
  116. package/build/math/vector3d.d.ts.map +1 -1
  117. package/build/math/vertex.d.ts.map +1 -1
  118. package/build/particles/emitter.d.ts.map +1 -1
  119. package/build/particles/particle.d.ts +29 -2
  120. package/build/particles/particle.d.ts.map +1 -1
  121. package/build/particles/settings.d.ts +104 -0
  122. package/build/particles/settings.d.ts.map +1 -1
  123. package/build/physics/adapter.d.ts +9 -1
  124. package/build/physics/adapter.d.ts.map +1 -1
  125. package/build/physics/bounds.d.ts +1 -1
  126. package/build/physics/bounds.d.ts.map +1 -1
  127. package/build/physics/broadphase/octree.d.ts +24 -0
  128. package/build/physics/broadphase/octree.d.ts.map +1 -1
  129. package/build/physics/broadphase/quadtree.d.ts +31 -0
  130. package/build/physics/broadphase/quadtree.d.ts.map +1 -1
  131. package/build/physics/builtin/body.d.ts +17 -2
  132. package/build/physics/builtin/body.d.ts.map +1 -1
  133. package/build/physics/builtin/builtin-adapter.d.ts.map +1 -1
  134. package/build/physics/builtin/detector.d.ts +0 -1
  135. package/build/physics/builtin/detector.d.ts.map +1 -1
  136. package/build/physics/builtin/sat.d.ts +0 -7
  137. package/build/physics/builtin/sat3d.d.ts +46 -0
  138. package/build/physics/builtin/sat3d.d.ts.map +1 -1
  139. package/build/physics/response.d.ts +45 -62
  140. package/build/physics/response.d.ts.map +1 -1
  141. package/build/pool.d.ts +4 -0
  142. package/build/pool.d.ts.map +1 -1
  143. package/build/renderable/collectable.d.ts +6 -1
  144. package/build/renderable/collectable.d.ts.map +1 -1
  145. package/build/renderable/colorlayer.d.ts +17 -4
  146. package/build/renderable/colorlayer.d.ts.map +1 -1
  147. package/build/renderable/container.d.ts +23 -17
  148. package/build/renderable/container.d.ts.map +1 -1
  149. package/build/renderable/entity/entity.d.ts +12 -16
  150. package/build/renderable/entity/entity.d.ts.map +1 -1
  151. package/build/renderable/frameAnimation.d.ts +1 -1
  152. package/build/renderable/groundshadow.d.ts +1 -0
  153. package/build/renderable/groundshadow.d.ts.map +1 -1
  154. package/build/renderable/imagelayer.d.ts +12 -5
  155. package/build/renderable/imagelayer.d.ts.map +1 -1
  156. package/build/renderable/instanced_mesh.d.ts +56 -7
  157. package/build/renderable/instanced_mesh.d.ts.map +1 -1
  158. package/build/renderable/mesh.d.ts +369 -4
  159. package/build/renderable/mesh.d.ts.map +1 -1
  160. package/build/renderable/nineslicesprite.d.ts +3 -13
  161. package/build/renderable/nineslicesprite.d.ts.map +1 -1
  162. package/build/renderable/renderable.d.ts +129 -28
  163. package/build/renderable/renderable.d.ts.map +1 -1
  164. package/build/renderable/sprite.d.ts +7 -20
  165. package/build/renderable/sprite.d.ts.map +1 -1
  166. package/build/renderable/sprite3d.d.ts +31 -16
  167. package/build/renderable/sprite3d.d.ts.map +1 -1
  168. package/build/renderable/text/bitmaptext.d.ts +76 -5
  169. package/build/renderable/text/bitmaptext.d.ts.map +1 -1
  170. package/build/renderable/text/bitmaptextdata.d.ts +1 -5
  171. package/build/renderable/text/bitmaptextdata.d.ts.map +1 -1
  172. package/build/renderable/text/glypheffect.d.ts +44 -0
  173. package/build/renderable/text/glypheffect.d.ts.map +1 -0
  174. package/build/renderable/text/text.d.ts +22 -3
  175. package/build/renderable/text/text.d.ts.map +1 -1
  176. package/build/renderable/text/textmetrics.d.ts +2 -0
  177. package/build/renderable/text/textmetrics.d.ts.map +1 -1
  178. package/build/renderable/trail.d.ts +0 -1
  179. package/build/renderable/trail.d.ts.map +1 -1
  180. package/build/renderable/trail3d.d.ts +174 -0
  181. package/build/renderable/trail3d.d.ts.map +1 -0
  182. package/build/renderable/trigger.d.ts +28 -5
  183. package/build/renderable/trigger.d.ts.map +1 -1
  184. package/build/renderable/ui/panelpaint.d.ts +5 -0
  185. package/build/renderable/ui/panelpaint.d.ts.map +1 -0
  186. package/build/renderable/ui/progressbar.d.ts +192 -0
  187. package/build/renderable/ui/progressbar.d.ts.map +1 -0
  188. package/build/renderable/ui/uibaseelement.d.ts +48 -3
  189. package/build/renderable/ui/uibaseelement.d.ts.map +1 -1
  190. package/build/renderable/ui/uipanel.d.ts +245 -0
  191. package/build/renderable/ui/uipanel.d.ts.map +1 -0
  192. package/build/renderable/ui/uispriteelement.d.ts +19 -3
  193. package/build/renderable/ui/uispriteelement.d.ts.map +1 -1
  194. package/build/renderable/ui/uitextbutton.d.ts +30 -1
  195. package/build/renderable/ui/uitextbutton.d.ts.map +1 -1
  196. package/build/state/state.d.ts.map +1 -1
  197. package/build/system/bootstrap.d.ts.map +1 -1
  198. package/build/system/legacy_pool.d.ts +24 -4
  199. package/build/system/legacy_pool.d.ts.map +1 -1
  200. package/build/system/pool.d.ts +15 -8
  201. package/build/system/pool.d.ts.map +1 -1
  202. package/build/tweens/tween.d.ts +50 -3
  203. package/build/tweens/tween.d.ts.map +1 -1
  204. package/build/video/canvas/canvas_renderer.d.ts +34 -23
  205. package/build/video/canvas/canvas_renderer.d.ts.map +1 -1
  206. package/build/video/effects/blendEffect.d.ts +0 -1
  207. package/build/video/effects/bloom.d.ts +72 -0
  208. package/build/video/effects/bloom.d.ts.map +1 -0
  209. package/build/video/effects/blur.d.ts +3 -2
  210. package/build/video/effects/blur.d.ts.map +1 -1
  211. package/build/video/effects/chromaticAberration.d.ts +3 -2
  212. package/build/video/effects/chromaticAberration.d.ts.map +1 -1
  213. package/build/video/effects/colorMatrix.d.ts +3 -2
  214. package/build/video/effects/colorMatrix.d.ts.map +1 -1
  215. package/build/video/effects/desaturate.d.ts +10 -2
  216. package/build/video/effects/desaturate.d.ts.map +1 -1
  217. package/build/video/effects/dissolve.d.ts +3 -2
  218. package/build/video/effects/dissolve.d.ts.map +1 -1
  219. package/build/video/effects/dropShadow.d.ts +3 -2
  220. package/build/video/effects/dropShadow.d.ts.map +1 -1
  221. package/build/video/effects/flash.d.ts +3 -2
  222. package/build/video/effects/flash.d.ts.map +1 -1
  223. package/build/video/effects/glow.d.ts +3 -2
  224. package/build/video/effects/glow.d.ts.map +1 -1
  225. package/build/video/effects/hologram.d.ts +3 -2
  226. package/build/video/effects/hologram.d.ts.map +1 -1
  227. package/build/video/effects/invert.d.ts +10 -2
  228. package/build/video/effects/invert.d.ts.map +1 -1
  229. package/build/video/effects/outline.d.ts +3 -2
  230. package/build/video/effects/outline.d.ts.map +1 -1
  231. package/build/video/effects/pixelate.d.ts +3 -2
  232. package/build/video/effects/pixelate.d.ts.map +1 -1
  233. package/build/video/effects/radialGradient.d.ts +8 -3
  234. package/build/video/effects/radialGradient.d.ts.map +1 -1
  235. package/build/video/effects/scanline.d.ts +3 -2
  236. package/build/video/effects/scanline.d.ts.map +1 -1
  237. package/build/video/effects/sepia.d.ts +10 -2
  238. package/build/video/effects/sepia.d.ts.map +1 -1
  239. package/build/video/effects/shadereffect.d.ts +10 -4
  240. package/build/video/effects/shadereffect.d.ts.map +1 -1
  241. package/build/video/effects/shine.d.ts +3 -2
  242. package/build/video/effects/shine.d.ts.map +1 -1
  243. package/build/video/effects/tintPulse.d.ts +3 -7
  244. package/build/video/effects/tintPulse.d.ts.map +1 -1
  245. package/build/video/effects/tonemap.d.ts +121 -0
  246. package/build/video/effects/tonemap.d.ts.map +1 -0
  247. package/build/video/effects/vignette.d.ts +3 -2
  248. package/build/video/effects/vignette.d.ts.map +1 -1
  249. package/build/video/effects/wave.d.ts +3 -7
  250. package/build/video/effects/wave.d.ts.map +1 -1
  251. package/build/video/gpu/batcher.d.ts +8 -2
  252. package/build/video/gpu/batcher.d.ts.map +1 -1
  253. package/build/video/gpu/vertexformat.d.ts +26 -0
  254. package/build/video/gpu/vertexformat.d.ts.map +1 -1
  255. package/build/video/gradient.d.ts +1 -1
  256. package/build/video/gradient.d.ts.map +1 -1
  257. package/build/video/renderer.d.ts +111 -7
  258. package/build/video/renderer.d.ts.map +1 -1
  259. package/build/video/renderstate.d.ts +2 -0
  260. package/build/video/renderstate.d.ts.map +1 -1
  261. package/build/video/rendertarget/canvasrendertarget.d.ts +3 -4
  262. package/build/video/rendertarget/canvasrendertarget.d.ts.map +1 -1
  263. package/build/video/rendertarget/render_target_pool.d.ts +0 -1
  264. package/build/video/rendertarget/rendertarget.d.ts +12 -5
  265. package/build/video/rendertarget/rendertarget.d.ts.map +1 -1
  266. package/build/video/rendertarget/webglrendertarget.d.ts +0 -1
  267. package/build/video/rendertarget/webglrendertarget.d.ts.map +1 -1
  268. package/build/video/rendertarget/webgpurendertarget.d.ts +24 -14
  269. package/build/video/rendertarget/webgpurendertarget.d.ts.map +1 -1
  270. package/build/video/texture/atlas.d.ts +2 -1
  271. package/build/video/texture/atlas.d.ts.map +1 -1
  272. package/build/video/texture/cache.d.ts +1 -3
  273. package/build/video/texture/frametexture.d.ts +0 -1
  274. package/build/video/texture/frametexture.d.ts.map +1 -1
  275. package/build/video/texture/noise_texture2d.d.ts +1 -0
  276. package/build/video/texture/noise_texture2d.d.ts.map +1 -1
  277. package/build/video/texture/texture2d.d.ts +6 -0
  278. package/build/video/texture/texture2d.d.ts.map +1 -1
  279. package/build/video/utils/autodetect.d.ts +0 -2
  280. package/build/video/webgl/batchers/batcher.d.ts +0 -9
  281. package/build/video/webgl/batchers/batcher.d.ts.map +1 -1
  282. package/build/video/webgl/batchers/lit_quad_batcher.d.ts +2 -0
  283. package/build/video/webgl/batchers/lit_quad_batcher.d.ts.map +1 -1
  284. package/build/video/webgl/batchers/material_batcher.d.ts +4 -2
  285. package/build/video/webgl/batchers/material_batcher.d.ts.map +1 -1
  286. package/build/video/webgl/batchers/mesh_batcher.d.ts +0 -3
  287. package/build/video/webgl/batchers/mesh_batcher.d.ts.map +1 -1
  288. package/build/video/webgl/batchers/quad_batcher.d.ts +4 -0
  289. package/build/video/webgl/batchers/quad_batcher.d.ts.map +1 -1
  290. package/build/video/webgl/buffer/index.d.ts +0 -1
  291. package/build/video/webgl/buffer/retained_geometry.d.ts +0 -1
  292. package/build/video/webgl/glshader.d.ts +5 -3
  293. package/build/video/webgl/glshader.d.ts.map +1 -1
  294. package/build/video/webgl/renderers/tmxlayer/orthogonal.d.ts +0 -4
  295. package/build/video/webgl/texture/store.d.ts +0 -1
  296. package/build/video/webgl/webgl_renderer.d.ts +63 -24
  297. package/build/video/webgl/webgl_renderer.d.ts.map +1 -1
  298. package/build/video/webgpu/batchers/mesh_batcher.d.ts +0 -3
  299. package/build/video/webgpu/batchers/mesh_batcher.d.ts.map +1 -1
  300. package/build/video/webgpu/batchers/quad_batcher.d.ts +0 -2
  301. package/build/video/webgpu/batchers/quad_batcher.d.ts.map +1 -1
  302. package/build/video/webgpu/batchers/webgpu_batcher.d.ts +0 -2
  303. package/build/video/webgpu/batchers/webgpu_batcher.d.ts.map +1 -1
  304. package/build/video/webgpu/pipeline/cache.d.ts.map +1 -1
  305. package/build/video/webgpu/renderers/tmxlayer/orthogonal.d.ts +0 -2
  306. package/build/video/webgpu/texture/frametexture.d.ts +0 -2
  307. package/build/video/webgpu/texture/frametexture.d.ts.map +1 -1
  308. package/build/video/webgpu/texture/store.d.ts +0 -1
  309. package/build/video/webgpu/webgpu_renderer.d.ts +7 -75
  310. package/build/video/webgpu/webgpu_renderer.d.ts.map +1 -1
  311. package/package.json +2 -2
  312. package/skills/AGENTS.md +1 -1
  313. package/skills/melonjs/SKILL.md +2 -0
  314. package/skills/melonjs-3d/SKILL.md +454 -22
  315. package/skills/melonjs-3d-assets/SKILL.md +111 -10
  316. package/skills/melonjs-audio/SKILL.md +229 -8
  317. package/skills/melonjs-camera-and-drawing/SKILL.md +127 -1
  318. package/skills/melonjs-display-and-scaling/SKILL.md +273 -0
  319. package/skills/melonjs-effects-and-shaders/SKILL.md +341 -29
  320. package/skills/melonjs-events/SKILL.md +8 -6
  321. package/skills/melonjs-input/SKILL.md +147 -7
  322. package/skills/melonjs-math/SKILL.md +313 -0
  323. package/skills/melonjs-particles-and-trails/SKILL.md +189 -13
  324. package/skills/melonjs-performance/SKILL.md +131 -23
  325. package/skills/melonjs-physics/SKILL.md +103 -28
  326. package/skills/melonjs-renderables/SKILL.md +8 -2
  327. package/skills/melonjs-scenes-and-state/SKILL.md +134 -3
  328. package/skills/melonjs-sprites-and-animation/SKILL.md +9 -4
  329. package/skills/melonjs-tilemaps/SKILL.md +40 -12
  330. package/skills/melonjs-ui-and-text/SKILL.md +546 -7
  331. package/build/level/gltf/srgb.d.ts +0 -20
  332. package/build/level/gltf/srgb.d.ts.map +0 -1
@@ -0,0 +1,273 @@
1
+ ---
2
+ name: melonjs-display-and-scaling
3
+ description: "Use this skill when a melonJS game looks blurry, soft, shimmering or cropped, or when choosing how the canvas fills its page. Covers the design resolution, scale and scaleMethod, scaleTarget, scaleRounding for pixel-perfect integer scaling, antiAlias, textureFilter, subPixel, devicePixelRatio, and which setting does which job. Triggers on: blurry, soft, fuzzy, shimmering, pixel art, pixel perfect, crisp, nearest, linear, scale, scaleMethod, scaleTarget, scaleRounding, integer scaling, antiAlias, textureFilter, subPixel, devicePixelRatio, retina, hidpi, design resolution, canvas size, canvas cropped, letterbox, image-rendering, upscale, resolution."
4
+ license: MIT
5
+ ---
6
+
7
+ # Display and scaling
8
+
9
+ Seven settings decide how a game looks on screen, and they are easy to get
10
+ individually right and collectively wrong. This is what each one actually
11
+ does, and which one to reach for.
12
+
13
+ ## The four jobs
14
+
15
+ A pixel travels from your source art to a physical pixel through four
16
+ separate decisions. Knowing which setting owns which is most of the work.
17
+
18
+ | job | setting | what it decides |
19
+ |---|---|---|
20
+ | how big the frame is drawn | `width`/`height` on `Application` | the design resolution everything is authored against |
21
+ | how it uses the space | `scale`, `scaleMethod`, `scaleTarget` | fit, fill, stretch, and what it measures to decide |
22
+ | may the factor be fractional | `scaleRounding` | whole device pixels per source pixel, or any factor |
23
+ | how a texture is sampled | `antiAlias`, `textureFilter` | nearest or linear, and the CSS upscale filter |
24
+
25
+ `subPixel` is a fifth, orthogonal to all of them: it decides whether a
26
+ renderable may sit on a fractional position WITHIN the frame.
27
+
28
+ ## Design resolution
29
+
30
+ ```js
31
+ const app = new Application(480, 270, { scale: "auto" });
32
+ ```
33
+
34
+ The game is drawn at 480x270 whatever the window is, and the canvas is scaled
35
+ to the container. Everything in world coordinates is in those units. This is
36
+ the usual arrangement: author once, scale to whatever you are given.
37
+
38
+ ## `scale` and `scaleMethod`
39
+
40
+ `scale: "auto"` turns on automatic scaling; a number is a fixed multiplier and
41
+ `scaleMethod` is then ignored.
42
+
43
+ `scaleMethod` decides how the available space is used:
44
+
45
+ - **`"fit"`** keeps the design resolution and the aspect ratio, scaling to the
46
+ largest factor that fits. Leftover space becomes margin. This is the one to
47
+ use when the game is authored for a fixed frame.
48
+ - **`"fill-min"` / `"fill-max"`** keep the aspect ratio but RESIZE the
49
+ renderer, so the design resolution changes with the window and the game sees
50
+ more or less of the world.
51
+ - **`"flex"`, `"flex-width"`, `"flex-height"`** resize the renderer on one or
52
+ both axes.
53
+ - **`"stretch"`** scales each axis independently, so the aspect ratio is not
54
+ preserved and circles become ovals.
55
+ - **`"manual"`** does nothing automatic.
56
+
57
+ The distinction that matters: **`fit` scales a fixed frame; everything else
58
+ changes how much of the world is visible.** A game whose layout assumes a
59
+ known frame wants `fit`.
60
+
61
+ ## `scaleTarget`: what gets measured
62
+
63
+ Automatic scaling measures **the parent of the element the canvas is mounted
64
+ in**, not the element itself. If that grandparent is not the box you meant,
65
+ the canvas is sized wrongly, and the failure is quiet.
66
+
67
+ The case that bites: a canvas container that is `position: fixed` or
68
+ `absolute` contributes no height to its parent, so the parent measures only
69
+ whatever else is in it. If that parent is `<body>`, the engine falls back to
70
+ the window size and the canvas ends up larger than the box it lives in,
71
+ cropped by whatever sits above it.
72
+
73
+ ```js
74
+ new Application(1024, 576, {
75
+ parent: "screen",
76
+ scale: "auto",
77
+ // measure THIS, rather than guessing from the DOM shape
78
+ scaleTarget: document.getElementById("stage"),
79
+ });
80
+ ```
81
+
82
+ Either name the element with `scaleTarget`, or give the canvas container a
83
+ parent whose box is the area you want filled. If the canvas is cropped or
84
+ overflows on resize, this is the first thing to check.
85
+
86
+ ## `scaleRounding`: whole device pixels
87
+
88
+ ```js
89
+ new Application(480, 270, {
90
+ scale: "auto",
91
+ scaleMethod: "fit",
92
+ scaleRounding: "integer", // default "fractional"
93
+ });
94
+ ```
95
+
96
+ `"fractional"` fills the container exactly, at whatever factor that takes. A
97
+ 480 wide design in a 1280 wide container is scaled by 2.667, so some source
98
+ pixels cover three screen pixels and some cover two. Pixel art shows this as
99
+ uneven glyph stems and shimmering edges, and browsers resolve the unevenness
100
+ differently, so the same scene can look crisp in one and soft in another.
101
+
102
+ `"integer"` rounds the factor DOWN so every source pixel covers the same whole
103
+ number of device pixels, and letterboxes with the space left over. That trade,
104
+ crisp pixels for black bars, is the whole decision.
105
+
106
+ ### What it costs
107
+
108
+ More than "some letterboxing", and the size of it is decided by
109
+ `devicePixelRatio` as much as by the window. A higher ratio has more device
110
+ pixels to round among, so it lands closer to the factor it wanted. For a
111
+ 480x270 design, which is exactly a quarter of 1920x1080:
112
+
113
+ | container | ratio | fit | integer | presented | area lost |
114
+ |---|---|---|---|---|---|
115
+ | 1920x1080 | 1 or 2 | 4.000 | 4 / 8 | 1920x1080 | none |
116
+ | 1440x810 | 1 | 3.000 | 3 | 1440x810 | none |
117
+ | 960x540 | 1 | 2.000 | 2 | 960x540 | none |
118
+ | 1280x720 | 2 | 2.667 | 5 | 1200x675 | 12% |
119
+ | 2560x1440 | 2 | 5.333 | 10 | 2400x1350 | 12% |
120
+ | 1280x720 | 1 | 2.667 | 2 | 960x540 | **44%** |
121
+ | 1366x768 | 1 | 2.844 | 2 | 960x540 | **51%** |
122
+
123
+ So the decision is mostly made when the design resolution is chosen, not when
124
+ this setting is. One that divides the sizes you expect costs nothing; one that
125
+ does not can give up half the screen on a 1x display, and 1366x768 laptops are
126
+ not rare. A game that must fill the window on any machine should stay
127
+ fractional and accept the uneven pixels.
128
+
129
+ Two things to know:
130
+
131
+ - It applies to **`scaleMethod: "fit"` only.** Every other method resizes the
132
+ renderer to the container, so the design resolution moves and there is no
133
+ fixed factor to round.
134
+ - The rounding happens in **device** pixels. `devicePixelRatio` multiplies the
135
+ CSS size on the way to real pixels, so rounding the CSS factor would let the
136
+ fraction straight back in: a factor of 2 at a ratio of 1.25 is 2.5 device
137
+ pixels per source pixel.
138
+
139
+ ## `antiAlias` does three things
140
+
141
+ This is the setting most likely to surprise, because it is not one switch:
142
+
143
+ 1. the texture filter, but only while `textureFilter` is `"auto"` (the
144
+ default), which TRACKS it: linear when on, nearest when off. Setting
145
+ `textureFilter` explicitly decouples the two
146
+ 2. `imageSmoothingEnabled` on the 2D context
147
+ 3. the canvas CSS `image-rendering`: `pixelated` when off, `auto` when on
148
+
149
+ So `antiAlias: false` gives hard-edged textures AND a hard-edged upscale of
150
+ the whole frame. That is usually what a pixel-art game wants, and usually NOT
151
+ what a smooth 3D scene wants, because it also disables MSAA.
152
+
153
+ `textureFilter: "nearest" | "linear"` separates the texture half, so a scene
154
+ can have smooth model edges and nearest-sampled sprites. The presentation half
155
+ is not separable: there is no way to get MSAA silhouettes and a hard-edged
156
+ upscale at the same time.
157
+
158
+ ## `subPixel` is about position, not scale
159
+
160
+ `subPixel: false` (the default) truncates a renderable's translation to whole
161
+ pixels inside the frame. It is `|0`, so it truncates **toward zero** rather
162
+ than rounding, which is worth knowing when something travels a short distance:
163
+ an offset that should swing between -3 and +3 lands on -2 and +2, and parks at
164
+ the extremes for longer than it should.
165
+
166
+ It does nothing about how the frame reaches the screen. A game that carefully
167
+ snaps positions and is then scaled by 2.667 has thrown that work away at the
168
+ last step, which is the contradiction `scaleRounding: "integer"` exists to
169
+ resolve.
170
+
171
+ ## Soft text next to crisp sprites
172
+
173
+ If everything is crisp EXCEPT the text, the scale factor is not the cause: a
174
+ fractional factor softens the whole frame equally. The text is different
175
+ because of how it is made.
176
+
177
+ `Text` draws through the browser's `fillText`, which anti-aliases glyph edges
178
+ into partial-alpha pixels. Measured on one label at 16px: **171 distinct
179
+ partial alpha levels**. Nothing in the canvas API turns that off. `antiAlias`
180
+ and the `imageSmoothingEnabled` that `CanvasRenderTarget` sets govern IMAGE
181
+ drawing, not glyph rasterisation.
182
+
183
+ So the label arrives already soft, and the upscale then magnifies each grey
184
+ edge pixel into a grey block, sitting beside sprites that were hard-edged to
185
+ begin with and stay hard-edged under nearest sampling.
186
+
187
+ It also explains the same scene looking crisp in one browser and soft in
188
+ another at identical size and settings: engines use different font
189
+ rasterisers, with different hinting and anti-aliasing, so they bake DIFFERENT
190
+ textures from the same font at the same size.
191
+
192
+ **Use `BitmapText` for a game that upscales.** A pixel-font atlas is
193
+ hard-edged source art like every other texture, so it survives magnification
194
+ the way the sprites do. Raising the design resolution only shrinks the
195
+ magnification of anti-aliasing that is still there, so it softens the symptom
196
+ rather than removing it, and `scaleRounding` does nothing for this at all.
197
+
198
+ Keep `Text` where the frame is not upscaled much, or where the label is meant
199
+ to look smooth.
200
+
201
+ ### Baking an atlas from a face you already use
202
+
203
+ Swapping in a bitmap face means generating one, and three things decide
204
+ whether it comes out looking like the original:
205
+
206
+ - **Threshold the coverage.** Hard edges are the whole point, so every pixel
207
+ has to end up fully on or fully off. Hardening only the ALPHA is not enough:
208
+ an outlined glyph keeps a soft stroke-to-fill blend INSIDE the silhouette,
209
+ which still reads as blur once magnified. Pick the colours from a mask.
210
+ - **Bake each size at that size, and draw it at a ratio of 1.** `size` on
211
+ `BitmapText` is a ratio of the authored size, and a bitmap face has the sizes
212
+ it was baked at. Doubling a smaller atlas halves the detail; a ratio below 1
213
+ drops whole stems; a fractional ratio resamples hard pixels unevenly. One
214
+ atlas per step of the type scale.
215
+ - **Grow the outline outward, but carve it INWARD around a counter.** This is
216
+ the one that costs the most time. A stroke drawn by the canvas is centred on
217
+ the contour, so around an enclosed hole it eats into the letter and the hole
218
+ keeps its size. Dilating a mask outward instead grows black INTO the hole
219
+ from every side, which closes anything under about 3px: the letter loses its
220
+ counter and reads as a blob. Take the rim from the fill side and the hole
221
+ survives at every size. Neither leaving holes unrimmed nor closing the small
222
+ ones is a substitute — both were tried and both look wrong.
223
+
224
+ Two traps in the generator itself:
225
+
226
+ - A face whose glyphs overshoot the `textBaseline` origin is clipped by a tight
227
+ cell, and the symptom is an outline that goes missing along one edge of some
228
+ glyphs. Pad the cell by a fraction of the size, and assert that no glyph's
229
+ ink reaches its border.
230
+ - The threshold decides the TOPOLOGY, not just the weight. A notch or a narrow
231
+ gap in a letterform closes over at a full threshold and becomes an isolated
232
+ hole, which then bakes as a black blob sitting on the glyph. Thinner, the
233
+ same feature stays joined to the background and reads as the face intends.
234
+ So a small size may want a thinner fill than a large one, and the way to see
235
+ it is to magnify one glyph, not a whole line.
236
+
237
+ ## A pixel-art setup
238
+
239
+ ```js
240
+ const app = new Application(480, 270, {
241
+ scale: "auto",
242
+ scaleMethod: "fit",
243
+ scaleRounding: "integer", // whole device pixels, letterbox the rest
244
+ antiAlias: false, // nearest textures, hard-edged upscale
245
+ // subPixel: false is already the default
246
+ });
247
+ ```
248
+
249
+ ## A smooth 3D setup
250
+
251
+ ```js
252
+ const app = new Application(1024, 576, {
253
+ scale: "auto",
254
+ scaleMethod: "fit",
255
+ antiAlias: true, // MSAA and a filtered upscale
256
+ textureFilter: "nearest", // but keep blocky textures if the art is blocky
257
+ });
258
+ ```
259
+
260
+ ## Symptoms
261
+
262
+ | symptom | cause |
263
+ |---|---|
264
+ | pixel art is blurry or shimmers | the frame is upscaled by a fractional factor; set `scaleRounding: "integer"` |
265
+ | crisp in one browser, soft in another | the same fractional factor, which engines distribute differently under `pixelated` |
266
+ | the canvas is cropped or overflows its box | automatic scaling measured the wrong element; name it with `scaleTarget` |
267
+ | the canvas grows on every resize | the measured ancestor is auto-sized around the canvas itself |
268
+ | things shimmer as they move | fractional positions; check `subPixel`, and that the scale factor is whole |
269
+ | 3D model edges are jagged | `antiAlias: false` also disables MSAA; turn it on and use `textureFilter` for textures |
270
+ | textures are smoothed when they should be blocky | `antiAlias: true` makes the default texture filter linear; set `textureFilter: "nearest"` |
271
+ | `scaleRounding: "integer"` changes nothing | it applies to `scaleMethod: "fit"` only; the others resize the renderer |
272
+ | text is soft but sprites are crisp | the glyphs were anti-aliased when `Text` baked them; use `BitmapText` (see below) |
273
+ | the game shows more world on a bigger window | that is `fill-*` or `flex-*` doing their job; use `"fit"` to keep a fixed frame |