melonjs 20.2.0 → 20.4.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 +86 -8
- package/build/application/application.d.ts +0 -17
- package/build/application/application.d.ts.map +1 -1
- package/build/application/settings.d.ts +6 -2
- package/build/application/settings.d.ts.map +1 -1
- package/build/audio/audio.d.ts +2 -2
- package/build/audio/audio.d.ts.map +1 -1
- package/build/audio/backend/buffer.d.ts +26 -0
- package/build/audio/backend/buffer.d.ts.map +1 -0
- package/build/audio/backend/cache.d.ts +2 -0
- package/build/audio/backend/cache.d.ts.map +1 -0
- package/build/audio/backend/core.d.ts +24 -0
- package/build/audio/backend/core.d.ts.map +1 -0
- package/build/audio/backend/engine.d.ts +35 -0
- package/build/audio/backend/engine.d.ts.map +1 -0
- package/build/audio/backend/sound.d.ts +29 -0
- package/build/audio/backend/sound.d.ts.map +1 -0
- package/build/audio/backend/spatial.d.ts +191 -0
- package/build/audio/backend/spatial.d.ts.map +1 -0
- package/build/audio/backend/types.d.ts +107 -0
- package/build/audio/backend/types.d.ts.map +1 -0
- package/build/audio/backend/voice.d.ts +8 -0
- package/build/audio/backend/voice.d.ts.map +1 -0
- package/build/audio/playback.d.ts +49 -4
- package/build/audio/playback.d.ts.map +1 -1
- package/build/audio/procedural.d.ts.map +1 -1
- package/build/audio/state.d.ts +69 -0
- package/build/audio/state.d.ts.map +1 -0
- package/build/audio/types.d.ts +93 -1
- package/build/audio/types.d.ts.map +1 -1
- package/build/camera/camera2d.d.ts +0 -68
- package/build/camera/camera2d.d.ts.map +1 -1
- package/build/camera/camera3d.d.ts +91 -84
- package/build/camera/camera3d.d.ts.map +1 -1
- package/build/camera/effects/fade_effect.d.ts +0 -5
- package/build/camera/effects/fade_effect.d.ts.map +1 -1
- package/build/camera/effects/mask_effect.d.ts +0 -5
- package/build/camera/effects/mask_effect.d.ts.map +1 -1
- package/build/camera/fog.d.ts +118 -0
- package/build/camera/fog.d.ts.map +1 -0
- package/build/const.d.ts +2 -2
- package/build/geometries/box3d.d.ts +0 -28
- package/build/geometries/box3d.d.ts.map +1 -1
- package/build/geometries/ellipse.d.ts +0 -20
- package/build/geometries/ellipse.d.ts.map +1 -1
- package/build/geometries/observablePoint.d.ts +0 -3
- package/build/geometries/observablePoint.d.ts.map +1 -1
- package/build/geometries/path2d.d.ts +0 -19
- package/build/geometries/path2d.d.ts.map +1 -1
- package/build/geometries/polygon.d.ts +0 -12
- package/build/geometries/polygon.d.ts.map +1 -1
- package/build/geometries/roundrect.d.ts +0 -18
- package/build/geometries/roundrect.d.ts.map +1 -1
- package/build/geometries/sphere.d.ts +0 -9
- package/build/geometries/sphere.d.ts.map +1 -1
- package/build/geometries/toarccanvas.d.ts.map +1 -1
- package/build/index.d.ts +1 -0
- package/build/index.d.ts.map +1 -1
- package/build/index.js +12150 -11289
- package/build/index.js.map +4 -4
- package/build/input/gamepad.d.ts.map +1 -1
- package/build/input/input.d.ts +19 -0
- package/build/input/input.d.ts.map +1 -1
- package/build/input/pointer.d.ts +0 -4
- package/build/input/pointer.d.ts.map +1 -1
- package/build/input/pointerevent.d.ts +0 -6
- package/build/input/pointerevent.d.ts.map +1 -1
- package/build/lang/deprecated.d.ts +4 -2
- package/build/lang/deprecated.d.ts.map +1 -1
- package/build/level/gltf/GLTFModel.d.ts +0 -81
- package/build/level/gltf/GLTFModel.d.ts.map +1 -1
- package/build/level/gltf/GLTFScene.d.ts +13 -44
- package/build/level/gltf/GLTFScene.d.ts.map +1 -1
- package/build/level/gltf/gltf_sampler.d.ts +1 -48
- package/build/level/gltf/gltf_sampler.d.ts.map +1 -1
- package/build/level/level.d.ts +195 -113
- package/build/level/level.d.ts.map +1 -1
- package/build/level/tiled/TMXGroup.d.ts +1 -65
- package/build/level/tiled/TMXGroup.d.ts.map +1 -1
- package/build/level/tiled/TMXLayer.d.ts +0 -44
- package/build/level/tiled/TMXLayer.d.ts.map +1 -1
- package/build/level/tiled/TMXObject.d.ts +1 -136
- package/build/level/tiled/TMXObject.d.ts.map +1 -1
- package/build/level/tiled/TMXObjectFactory.d.ts +1 -40
- package/build/level/tiled/TMXObjectFactory.d.ts.map +1 -1
- package/build/level/tiled/TMXTile.d.ts +1 -30
- package/build/level/tiled/TMXTile.d.ts.map +1 -1
- package/build/level/tiled/TMXTileMap.d.ts +0 -10
- package/build/level/tiled/TMXTileMap.d.ts.map +1 -1
- package/build/level/tiled/TMXTileset.d.ts +0 -113
- package/build/level/tiled/TMXTileset.d.ts.map +1 -1
- package/build/level/tiled/TMXTilesetGroup.d.ts +0 -1
- package/build/level/tiled/TMXTilesetGroup.d.ts.map +1 -1
- package/build/level/tiled/TMXUtils.d.ts +1 -43
- package/build/level/tiled/TMXUtils.d.ts.map +1 -1
- package/build/level/tiled/factories/shape.d.ts +1 -7
- package/build/level/tiled/factories/shape.d.ts.map +1 -1
- package/build/level/tiled/factories/text.d.ts +1 -7
- package/build/level/tiled/factories/text.d.ts.map +1 -1
- package/build/level/tiled/factories/tile.d.ts +1 -7
- package/build/level/tiled/factories/tile.d.ts.map +1 -1
- package/build/level/tiled/renderer/TMXHexagonalRenderer.d.ts +0 -60
- package/build/level/tiled/renderer/TMXHexagonalRenderer.d.ts.map +1 -1
- package/build/level/tiled/renderer/TMXIsometricRenderer.d.ts +0 -42
- package/build/level/tiled/renderer/TMXIsometricRenderer.d.ts.map +1 -1
- package/build/level/tiled/renderer/TMXObliqueRenderer.d.ts +0 -5
- package/build/level/tiled/renderer/TMXObliqueRenderer.d.ts.map +1 -1
- package/build/level/tiled/renderer/TMXOrthogonalRenderer.d.ts +0 -31
- package/build/level/tiled/renderer/TMXOrthogonalRenderer.d.ts.map +1 -1
- package/build/level/tiled/renderer/TMXRenderer.d.ts +2 -2
- package/build/level/tiled/renderer/TMXRenderer.d.ts.map +1 -1
- package/build/level/tiled/renderer/TMXStaggeredRenderer.d.ts.map +1 -1
- package/build/level/tiled/renderer/autodetect.d.ts +1 -6
- package/build/level/tiled/renderer/autodetect.d.ts.map +1 -1
- package/build/lighting/light2d.d.ts +0 -25
- package/build/lighting/light2d.d.ts.map +1 -1
- package/build/lighting/light3d.d.ts +0 -16
- package/build/lighting/light3d.d.ts.map +1 -1
- package/build/loader/loader.d.ts +46 -73
- package/build/loader/loader.d.ts.map +1 -1
- package/build/loader/loadingscreen.d.ts +0 -33
- package/build/loader/loadingscreen.d.ts.map +1 -1
- package/build/loader/parsers/aseprite.d.ts +0 -13
- package/build/loader/parsers/aseprite.d.ts.map +1 -1
- package/build/loader/parsers/audio.d.ts +2 -0
- package/build/loader/parsers/audio.d.ts.map +1 -0
- package/build/loader/parsers/binary.d.ts +1 -10
- package/build/loader/parsers/binary.d.ts.map +1 -1
- package/build/loader/parsers/compressed_textures/compressed_image.d.ts.map +1 -1
- package/build/loader/parsers/compressed_textures/parseDDS.d.ts +1 -7
- package/build/loader/parsers/compressed_textures/parseDDS.d.ts.map +1 -1
- package/build/loader/parsers/compressed_textures/parseKTX.d.ts +1 -7
- package/build/loader/parsers/compressed_textures/parseKTX.d.ts.map +1 -1
- package/build/loader/parsers/compressed_textures/parseKTX2.d.ts +1 -7
- package/build/loader/parsers/compressed_textures/parseKTX2.d.ts.map +1 -1
- package/build/loader/parsers/compressed_textures/parsePKM.d.ts +1 -7
- package/build/loader/parsers/compressed_textures/parsePKM.d.ts.map +1 -1
- package/build/loader/parsers/compressed_textures/parsePVR.d.ts +1 -7
- package/build/loader/parsers/compressed_textures/parsePVR.d.ts.map +1 -1
- package/build/loader/parsers/fontface.d.ts +1 -13
- package/build/loader/parsers/fontface.d.ts.map +1 -1
- package/build/loader/parsers/gltf.d.ts +1 -70
- package/build/loader/parsers/gltf.d.ts.map +1 -1
- package/build/loader/parsers/image.d.ts +1 -22
- package/build/loader/parsers/image.d.ts.map +1 -1
- package/build/loader/parsers/json.d.ts +1 -10
- package/build/loader/parsers/json.d.ts.map +1 -1
- package/build/loader/parsers/mtl.d.ts +1 -28
- package/build/loader/parsers/mtl.d.ts.map +1 -1
- package/build/loader/parsers/obj.d.ts +1 -59
- package/build/loader/parsers/obj.d.ts.map +1 -1
- package/build/loader/parsers/pbr.d.ts +1 -62
- package/build/loader/parsers/pbr.d.ts.map +1 -1
- package/build/loader/parsers/script.d.ts +1 -10
- package/build/loader/parsers/script.d.ts.map +1 -1
- package/build/loader/parsers/shader.d.ts +1 -52
- package/build/loader/parsers/shader.d.ts.map +1 -1
- package/build/loader/parsers/tmx.d.ts +1 -10
- package/build/loader/parsers/tmx.d.ts.map +1 -1
- package/build/loader/parsers/video.d.ts +1 -10
- package/build/loader/parsers/video.d.ts.map +1 -1
- package/build/math/color.d.ts.map +1 -1
- package/build/math/noise.d.ts +0 -40
- package/build/math/noise.d.ts.map +1 -1
- package/build/math/observableVector2d.d.ts +0 -3
- package/build/math/observableVector2d.d.ts.map +1 -1
- package/build/math/observableVector3d.d.ts +0 -3
- package/build/math/observableVector3d.d.ts.map +1 -1
- package/build/math/vector2d.d.ts +0 -6
- package/build/math/vector2d.d.ts.map +1 -1
- package/build/math/vertex.d.ts +25 -0
- package/build/math/vertex.d.ts.map +1 -1
- package/build/particles/emitter.d.ts +0 -65
- package/build/particles/emitter.d.ts.map +1 -1
- package/build/particles/particle.d.ts +0 -81
- package/build/particles/particle.d.ts.map +1 -1
- package/build/physics/adapter.d.ts +3 -3
- package/build/physics/bounds.d.ts +0 -1
- package/build/physics/bounds.d.ts.map +1 -1
- package/build/physics/broadphase/broadphase.d.ts +0 -7
- package/build/physics/broadphase/broadphase.d.ts.map +1 -1
- package/build/physics/broadphase/octree.d.ts +0 -91
- package/build/physics/broadphase/octree.d.ts.map +1 -1
- package/build/physics/broadphase/quadtree.d.ts +0 -47
- package/build/physics/broadphase/quadtree.d.ts.map +1 -1
- package/build/physics/builtin/body.d.ts +5 -69
- package/build/physics/builtin/body.d.ts.map +1 -1
- package/build/physics/builtin/detector.d.ts +0 -312
- package/build/physics/builtin/detector.d.ts.map +1 -1
- package/build/physics/builtin/sat.d.ts +1 -48
- package/build/physics/builtin/sat.d.ts.map +1 -1
- package/build/physics/builtin/sat3d.d.ts +1 -56
- package/build/physics/builtin/sat3d.d.ts.map +1 -1
- package/build/physics/collision.d.ts +0 -2
- package/build/physics/collision.d.ts.map +1 -1
- package/build/physics/response.d.ts +0 -1
- package/build/physics/response.d.ts.map +1 -1
- package/build/physics/world.d.ts.map +1 -1
- package/build/plugin/plugin.d.ts +9 -1
- package/build/plugin/plugin.d.ts.map +1 -1
- package/build/polyfill/index.d.ts +1 -4
- package/build/polyfill/index.d.ts.map +1 -1
- package/build/renderable/anchorPoint.d.ts +1 -73
- package/build/renderable/anchorPoint.d.ts.map +1 -1
- package/build/renderable/animation.d.ts +0 -7
- package/build/renderable/animation.d.ts.map +1 -1
- package/build/renderable/colorlayer.d.ts +0 -5
- package/build/renderable/colorlayer.d.ts.map +1 -1
- package/build/renderable/container.d.ts +0 -55
- package/build/renderable/container.d.ts.map +1 -1
- package/build/renderable/draggable.d.ts +0 -5
- package/build/renderable/draggable.d.ts.map +1 -1
- package/build/renderable/dragndrop.d.ts +1 -12
- package/build/renderable/dragndrop.d.ts.map +1 -1
- package/build/renderable/entity/entity.d.ts +0 -8
- package/build/renderable/entity/entity.d.ts.map +1 -1
- package/build/renderable/frameAnimation.d.ts +0 -41
- package/build/renderable/frameAnimation.d.ts.map +1 -1
- package/build/renderable/groundshadow.d.ts +1 -91
- package/build/renderable/groundshadow.d.ts.map +1 -1
- package/build/renderable/imagelayer.d.ts +0 -29
- package/build/renderable/imagelayer.d.ts.map +1 -1
- package/build/renderable/instanced_mesh.d.ts +26 -104
- package/build/renderable/instanced_mesh.d.ts.map +1 -1
- package/build/renderable/mesh.d.ts +145 -140
- package/build/renderable/mesh.d.ts.map +1 -1
- package/build/renderable/nineslicesprite.d.ts +0 -4
- package/build/renderable/nineslicesprite.d.ts.map +1 -1
- package/build/renderable/renderable.d.ts +17 -54
- package/build/renderable/renderable.d.ts.map +1 -1
- package/build/renderable/sprite.d.ts +7 -52
- package/build/renderable/sprite.d.ts.map +1 -1
- package/build/renderable/sprite3d.d.ts +0 -95
- package/build/renderable/sprite3d.d.ts.map +1 -1
- package/build/renderable/text/bitmaptext.d.ts +0 -14
- package/build/renderable/text/bitmaptext.d.ts.map +1 -1
- package/build/renderable/text/bitmaptextdata.d.ts +0 -22
- package/build/renderable/text/bitmaptextdata.d.ts.map +1 -1
- package/build/renderable/text/glyph.d.ts +1 -39
- package/build/renderable/text/glyph.d.ts.map +1 -1
- package/build/renderable/text/text.d.ts +0 -20
- package/build/renderable/text/text.d.ts.map +1 -1
- package/build/renderable/text/textstyle.d.ts +1 -5
- package/build/renderable/text/textstyle.d.ts.map +1 -1
- package/build/renderable/trail.d.ts +0 -29
- package/build/renderable/trail.d.ts.map +1 -1
- package/build/renderable/trigger.d.ts +0 -6
- package/build/renderable/trigger.d.ts.map +1 -1
- package/build/renderable/ui/uibaseelement.d.ts +0 -40
- package/build/renderable/ui/uibaseelement.d.ts.map +1 -1
- package/build/renderable/ui/uispriteelement.d.ts +0 -35
- package/build/renderable/ui/uispriteelement.d.ts.map +1 -1
- package/build/state/stage.d.ts +4 -68
- package/build/state/stage.d.ts.map +1 -1
- package/build/state/state.d.ts.map +1 -1
- package/build/system/device.d.ts +0 -12
- package/build/system/device.d.ts.map +1 -1
- package/build/system/dom.d.ts +1 -8
- package/build/system/dom.d.ts.map +1 -1
- package/build/system/event.d.ts +1 -1
- package/build/system/legacy_pool.d.ts +1 -6
- package/build/system/legacy_pool.d.ts.map +1 -1
- package/build/system/platform.d.ts +21 -2
- package/build/system/platform.d.ts.map +1 -1
- package/build/system/pool.d.ts +0 -9
- package/build/system/pool.d.ts.map +1 -1
- package/build/system/save.d.ts.map +1 -1
- package/build/system/timer.d.ts +0 -20
- package/build/system/timer.d.ts.map +1 -1
- package/build/tweens/tween.d.ts +0 -62
- package/build/tweens/tween.d.ts.map +1 -1
- package/build/utils/array-multimap.d.ts +1 -13
- package/build/utils/array-multimap.d.ts.map +1 -1
- package/build/utils/decode.d.ts.map +1 -1
- package/build/utils/fetchdata.d.ts +2 -0
- package/build/utils/fetchdata.d.ts.map +1 -0
- package/build/utils/utils.d.ts +0 -13
- package/build/utils/utils.d.ts.map +1 -1
- package/build/video/blendmodes.d.ts +1 -106
- package/build/video/blendmodes.d.ts.map +1 -1
- package/build/video/buffer/index.d.ts +1 -39
- package/build/video/buffer/index.d.ts.map +1 -1
- package/build/video/buffer/vertex.d.ts +1 -82
- package/build/video/buffer/vertex.d.ts.map +1 -1
- package/build/video/canvas/canvas_renderer.d.ts +7 -25
- package/build/video/canvas/canvas_renderer.d.ts.map +1 -1
- package/build/video/canvas_factory.d.ts +1 -24
- package/build/video/canvas_factory.d.ts.map +1 -1
- package/build/video/effects/blendEffect.d.ts +0 -54
- package/build/video/effects/blendEffect.d.ts.map +1 -1
- package/build/video/effects/blur.d.ts +4 -4
- package/build/video/effects/blur.d.ts.map +1 -1
- package/build/video/effects/chromaticAberration.d.ts +5 -5
- package/build/video/effects/chromaticAberration.d.ts.map +1 -1
- package/build/video/effects/colorMatrix.d.ts +5 -15
- package/build/video/effects/colorMatrix.d.ts.map +1 -1
- package/build/video/effects/desaturate.d.ts +5 -5
- package/build/video/effects/desaturate.d.ts.map +1 -1
- package/build/video/effects/dissolve.d.ts +4 -4
- package/build/video/effects/dissolve.d.ts.map +1 -1
- package/build/video/effects/dropShadow.d.ts +5 -5
- package/build/video/effects/dropShadow.d.ts.map +1 -1
- package/build/video/effects/flash.d.ts +4 -4
- package/build/video/effects/flash.d.ts.map +1 -1
- package/build/video/effects/glow.d.ts +5 -5
- package/build/video/effects/glow.d.ts.map +1 -1
- package/build/video/effects/glsl_realization.d.ts +1 -17
- package/build/video/effects/glsl_realization.d.ts.map +1 -1
- package/build/video/effects/hologram.d.ts +4 -4
- package/build/video/effects/hologram.d.ts.map +1 -1
- package/build/video/effects/invert.d.ts +5 -5
- package/build/video/effects/invert.d.ts.map +1 -1
- package/build/video/effects/outline.d.ts +6 -6
- package/build/video/effects/outline.d.ts.map +1 -1
- package/build/video/effects/pixelate.d.ts +4 -4
- package/build/video/effects/pixelate.d.ts.map +1 -1
- package/build/video/effects/radialGradient.d.ts +2 -3
- package/build/video/effects/radialGradient.d.ts.map +1 -1
- package/build/video/effects/scanline.d.ts +6 -6
- package/build/video/effects/scanline.d.ts.map +1 -1
- package/build/video/effects/sepia.d.ts +5 -5
- package/build/video/effects/sepia.d.ts.map +1 -1
- package/build/video/effects/shadereffect.d.ts +12 -123
- package/build/video/effects/shadereffect.d.ts.map +1 -1
- package/build/video/effects/shine.d.ts +3 -3
- package/build/video/effects/shine.d.ts.map +1 -1
- package/build/video/effects/tintPulse.d.ts +4 -4
- package/build/video/effects/tintPulse.d.ts.map +1 -1
- package/build/video/effects/vignette.d.ts +6 -6
- package/build/video/effects/vignette.d.ts.map +1 -1
- package/build/video/effects/wave.d.ts +4 -4
- package/build/video/effects/wave.d.ts.map +1 -1
- package/build/video/effects/wgsl/layout.d.ts +1 -27
- package/build/video/effects/wgsl/layout.d.ts.map +1 -1
- package/build/video/effects/wgsl/parse.d.ts +1 -8
- package/build/video/effects/wgsl/parse.d.ts.map +1 -1
- package/build/video/effects/wgsl/scaffold.d.ts +1 -42
- package/build/video/effects/wgsl/scaffold.d.ts.map +1 -1
- package/build/video/effects/wgsl_realization.d.ts +1 -82
- package/build/video/effects/wgsl_realization.d.ts.map +1 -1
- package/build/video/gpu/batcher.d.ts +1 -13
- package/build/video/gpu/batcher.d.ts.map +1 -1
- package/build/video/gpu/instancerecord.d.ts +1 -163
- package/build/video/gpu/instancerecord.d.ts.map +1 -1
- package/build/video/gpu/meshchunk.d.ts +1 -48
- package/build/video/gpu/meshchunk.d.ts.map +1 -1
- package/build/video/gpu/meshvertex.d.ts +1 -53
- package/build/video/gpu/meshvertex.d.ts.map +1 -1
- package/build/video/gpu/primitives.d.ts +1 -59
- package/build/video/gpu/primitives.d.ts.map +1 -1
- package/build/video/gpu/quadcorners.d.ts +1 -10
- package/build/video/gpu/quadcorners.d.ts.map +1 -1
- package/build/video/gpu/textureslots.d.ts +1 -121
- package/build/video/gpu/textureslots.d.ts.map +1 -1
- package/build/video/gpu/texturestore.d.ts +1 -138
- package/build/video/gpu/texturestore.d.ts.map +1 -1
- package/build/video/gpu/topology.d.ts.map +1 -1
- package/build/video/gpu/vertexformat.d.ts +0 -28
- package/build/video/gpu/vertexformat.d.ts.map +1 -1
- package/build/video/gradient.d.ts +0 -81
- package/build/video/gradient.d.ts.map +1 -1
- package/build/video/renderer.d.ts +21 -102
- package/build/video/renderer.d.ts.map +1 -1
- package/build/video/renderstate.d.ts +0 -51
- package/build/video/renderstate.d.ts.map +1 -1
- package/build/video/rendertarget/canvasrendertarget.d.ts +0 -10
- package/build/video/rendertarget/canvasrendertarget.d.ts.map +1 -1
- package/build/video/rendertarget/render_target_pool.d.ts +1 -82
- package/build/video/rendertarget/render_target_pool.d.ts.map +1 -1
- package/build/video/rendertarget/webglrendertarget.d.ts +1 -64
- package/build/video/rendertarget/webglrendertarget.d.ts.map +1 -1
- package/build/video/rendertarget/webgpurendertarget.d.ts +0 -8
- package/build/video/rendertarget/webgpurendertarget.d.ts.map +1 -1
- package/build/video/texture/atlas.d.ts +2 -76
- package/build/video/texture/atlas.d.ts.map +1 -1
- package/build/video/texture/cache.d.ts +0 -136
- package/build/video/texture/cache.d.ts.map +1 -1
- package/build/video/texture/frametexture.d.ts +1 -71
- package/build/video/texture/frametexture.d.ts.map +1 -1
- package/build/video/texture/noise_texture2d.d.ts +0 -43
- package/build/video/texture/noise_texture2d.d.ts.map +1 -1
- package/build/video/texture/parser/aseprite.d.ts +1 -8
- package/build/video/texture/parser/aseprite.d.ts.map +1 -1
- package/build/video/texture/parser/spritesheet.d.ts +1 -8
- package/build/video/texture/parser/spritesheet.d.ts.map +1 -1
- package/build/video/texture/parser/texturepacker.d.ts +1 -8
- package/build/video/texture/parser/texturepacker.d.ts.map +1 -1
- package/build/video/texture/resource.d.ts +0 -9
- package/build/video/texture/resource.d.ts.map +1 -1
- package/build/video/texture/texture2d.d.ts +0 -11
- package/build/video/texture/texture2d.d.ts.map +1 -1
- package/build/video/utils/autodetect.d.ts +1 -5
- package/build/video/utils/autodetect.d.ts.map +1 -1
- package/build/video/webgl/batchers/batcher.d.ts +0 -55
- package/build/video/webgl/batchers/batcher.d.ts.map +1 -1
- package/build/video/webgl/batchers/lit_mesh_batcher.d.ts +0 -14
- package/build/video/webgl/batchers/lit_mesh_batcher.d.ts.map +1 -1
- package/build/video/webgl/batchers/lit_quad_batcher.d.ts +0 -72
- package/build/video/webgl/batchers/lit_quad_batcher.d.ts.map +1 -1
- package/build/video/webgl/batchers/material_batcher.d.ts +0 -89
- package/build/video/webgl/batchers/material_batcher.d.ts.map +1 -1
- package/build/video/webgl/batchers/mesh_batcher.d.ts +14 -343
- package/build/video/webgl/batchers/mesh_batcher.d.ts.map +1 -1
- package/build/video/webgl/batchers/primitive_batcher.d.ts +0 -10
- package/build/video/webgl/batchers/primitive_batcher.d.ts.map +1 -1
- package/build/video/webgl/batchers/quad_batcher.d.ts +0 -30
- package/build/video/webgl/batchers/quad_batcher.d.ts.map +1 -1
- package/build/video/webgl/buffer/index.d.ts +1 -36
- package/build/video/webgl/buffer/index.d.ts.map +1 -1
- package/build/video/webgl/buffer/instance_buffer.d.ts +1 -53
- package/build/video/webgl/buffer/instance_buffer.d.ts.map +1 -1
- package/build/video/webgl/buffer/retained_geometry.d.ts +1 -81
- package/build/video/webgl/buffer/retained_geometry.d.ts.map +1 -1
- package/build/video/webgl/buffer/uniformblock.d.ts +1 -80
- package/build/video/webgl/buffer/uniformblock.d.ts.map +1 -1
- package/build/video/webgl/buffer/vertexstate.d.ts +1 -100
- package/build/video/webgl/buffer/vertexstate.d.ts.map +1 -1
- package/build/video/webgl/glshader.d.ts +2 -51
- package/build/video/webgl/glshader.d.ts.map +1 -1
- package/build/video/webgl/lighting/pack3d.d.ts +1 -47
- package/build/video/webgl/lighting/pack3d.d.ts.map +1 -1
- package/build/video/webgl/lighting/std140.d.ts +1 -109
- package/build/video/webgl/lighting/std140.d.ts.map +1 -1
- package/build/video/webgl/renderers/tmxlayer/orthogonal.d.ts +1 -103
- package/build/video/webgl/renderers/tmxlayer/orthogonal.d.ts.map +1 -1
- package/build/video/webgl/shaders/multitexture-lit.d.ts +1 -26
- package/build/video/webgl/shaders/multitexture-lit.d.ts.map +1 -1
- package/build/video/webgl/shaders/multitexture.d.ts +1 -9
- package/build/video/webgl/shaders/multitexture.d.ts.map +1 -1
- package/build/video/webgl/texture/store.d.ts +1 -50
- package/build/video/webgl/texture/store.d.ts.map +1 -1
- package/build/video/webgl/utils/attributes.d.ts +1 -11
- package/build/video/webgl/utils/attributes.d.ts.map +1 -1
- package/build/video/webgl/utils/maxtextures.d.ts +1 -36
- package/build/video/webgl/utils/maxtextures.d.ts.map +1 -1
- package/build/video/webgl/utils/precision.d.ts +1 -14
- package/build/video/webgl/utils/precision.d.ts.map +1 -1
- package/build/video/webgl/utils/program.d.ts +1 -5
- package/build/video/webgl/utils/program.d.ts.map +1 -1
- package/build/video/webgl/utils/samplercache.d.ts +1 -68
- package/build/video/webgl/utils/samplercache.d.ts.map +1 -1
- package/build/video/webgl/utils/string.d.ts +1 -21
- package/build/video/webgl/utils/string.d.ts.map +1 -1
- package/build/video/webgl/utils/topology.d.ts +1 -23
- package/build/video/webgl/utils/topology.d.ts.map +1 -1
- package/build/video/webgl/utils/uniforms.d.ts +1 -25
- package/build/video/webgl/utils/uniforms.d.ts.map +1 -1
- package/build/video/webgl/utils/vertexformat.d.ts +1 -26
- package/build/video/webgl/utils/vertexformat.d.ts.map +1 -1
- package/build/video/webgl/webgl_renderer.d.ts +24 -286
- package/build/video/webgl/webgl_renderer.d.ts.map +1 -1
- package/build/video/webgpu/batchers/lit_mesh_batcher.d.ts +0 -6
- package/build/video/webgpu/batchers/lit_mesh_batcher.d.ts.map +1 -1
- package/build/video/webgpu/batchers/lit_quad_batcher.d.ts +0 -8
- package/build/video/webgpu/batchers/lit_quad_batcher.d.ts.map +1 -1
- package/build/video/webgpu/batchers/mesh_batcher.d.ts +1 -230
- package/build/video/webgpu/batchers/mesh_batcher.d.ts.map +1 -1
- package/build/video/webgpu/batchers/primitive_batcher.d.ts.map +1 -1
- package/build/video/webgpu/batchers/quad_batcher.d.ts +0 -82
- package/build/video/webgpu/batchers/quad_batcher.d.ts.map +1 -1
- package/build/video/webgpu/buffer/arena.d.ts +1 -63
- package/build/video/webgpu/buffer/arena.d.ts.map +1 -1
- package/build/video/webgpu/buffer/instance_buffer.d.ts +1 -64
- package/build/video/webgpu/buffer/instance_buffer.d.ts.map +1 -1
- package/build/video/webgpu/buffer/retained_geometry.d.ts +1 -54
- package/build/video/webgpu/buffer/retained_geometry.d.ts.map +1 -1
- package/build/video/webgpu/buffer/uniformring.d.ts +1 -67
- package/build/video/webgpu/buffer/uniformring.d.ts.map +1 -1
- package/build/video/webgpu/effect_binding.d.ts +1 -16
- package/build/video/webgpu/effect_binding.d.ts.map +1 -1
- package/build/video/webgpu/pipeline/bindgroups.d.ts +1 -32
- package/build/video/webgpu/pipeline/bindgroups.d.ts.map +1 -1
- package/build/video/webgpu/pipeline/cache.d.ts +1 -163
- package/build/video/webgpu/pipeline/cache.d.ts.map +1 -1
- package/build/video/webgpu/renderers/tmxlayer/orthogonal.d.ts +1 -87
- package/build/video/webgpu/renderers/tmxlayer/orthogonal.d.ts.map +1 -1
- package/build/video/webgpu/shaders/mesh-instanced.d.ts +1 -43
- package/build/video/webgpu/shaders/mesh-instanced.d.ts.map +1 -1
- package/build/video/webgpu/texture/compressed.d.ts +1 -32
- package/build/video/webgpu/texture/compressed.d.ts.map +1 -1
- package/build/video/webgpu/texture/frametexture.d.ts +1 -62
- package/build/video/webgpu/texture/frametexture.d.ts.map +1 -1
- package/build/video/webgpu/texture/store.d.ts +1 -147
- package/build/video/webgpu/texture/store.d.ts.map +1 -1
- package/build/video/webgpu/webgpu_renderer.d.ts +2 -89
- package/build/video/webgpu/webgpu_renderer.d.ts.map +1 -1
- package/package.json +8 -11
- package/skills/AGENTS.md +67 -0
- package/skills/melonjs/SKILL.md +156 -0
- package/skills/melonjs-20-migration/SKILL.md +160 -0
- package/skills/melonjs-3d/SKILL.md +525 -0
- package/skills/melonjs-3d-assets/SKILL.md +258 -0
- package/skills/melonjs-audio/SKILL.md +236 -0
- package/skills/melonjs-camera-and-drawing/SKILL.md +175 -0
- package/skills/melonjs-deployment/SKILL.md +113 -0
- package/skills/melonjs-effects-and-shaders/SKILL.md +178 -0
- package/skills/melonjs-events/SKILL.md +159 -0
- package/skills/melonjs-getting-started/SKILL.md +183 -0
- package/skills/melonjs-input/SKILL.md +166 -0
- package/skills/melonjs-lighting/SKILL.md +139 -0
- package/skills/melonjs-loading-assets/SKILL.md +186 -0
- package/skills/melonjs-particles-and-trails/SKILL.md +136 -0
- package/skills/melonjs-performance/SKILL.md +183 -0
- package/skills/melonjs-physics/SKILL.md +321 -0
- package/skills/melonjs-plugins/SKILL.md +191 -0
- package/skills/melonjs-renderables/SKILL.md +214 -0
- package/skills/melonjs-renderer-backends/SKILL.md +173 -0
- package/skills/melonjs-scenes-and-state/SKILL.md +180 -0
- package/skills/melonjs-sprites-and-animation/SKILL.md +173 -0
- package/skills/melonjs-tilemaps/SKILL.md +213 -0
- package/skills/melonjs-ui-and-text/SKILL.md +65 -0
- package/build/audio/backend.d.ts +0 -140
- package/build/audio/backend.d.ts.map +0 -1
- package/build/loader/parsers/fetchdata.d.ts +0 -32
- package/build/loader/parsers/fetchdata.d.ts.map +0 -1
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: melonjs-performance
|
|
3
|
+
description: "Use this skill when a melonJS game drops frames, allocates heavily, or needs to scale to many objects. Covers object pooling, draw-call batching, atlases, baking with CanvasRenderTarget, instancing, culling and alwaysUpdate, the debug plugin, and where the real costs are. Triggers on: performance, slow, frame rate, fps, lag, pool, pool.register, pool.pull, batching, draw calls, InstancedMesh, culling, alwaysUpdate, inViewport, CanvasRenderTarget, optimise, profiling, debug plugin, memory."
|
|
4
|
+
license: MIT
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Performance
|
|
8
|
+
|
|
9
|
+
## Measure first
|
|
10
|
+
|
|
11
|
+
Register the debug plugin and read the numbers before changing anything:
|
|
12
|
+
|
|
13
|
+
```js
|
|
14
|
+
import { plugin } from "melonjs";
|
|
15
|
+
import { DebugPanelPlugin } from "@melonjs/debug-plugin";
|
|
16
|
+
|
|
17
|
+
await app.init();
|
|
18
|
+
plugin.register(DebugPanelPlugin, "debugPanel");
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
It reports frame time, draw calls, object counts, and can overlay collision
|
|
22
|
+
shapes and bounds. **Draw calls** is usually the number that matters.
|
|
23
|
+
|
|
24
|
+
## Batching: the biggest lever
|
|
25
|
+
|
|
26
|
+
Both GPU backends batch **across textures**, not just within one: the quad
|
|
27
|
+
batcher assigns each source image a texture unit and embeds the unit in the
|
|
28
|
+
vertex data, so several different images still flush as a single draw. The pool
|
|
29
|
+
is finite — the WebGL batcher gets `renderer.maxTextures` units (the
|
|
30
|
+
`maxTextures` application setting, `"auto"` = the device limit capped at 32), the
|
|
31
|
+
WebGPU batcher eight per segment. Overflow the pool and the batch flushes.
|
|
32
|
+
|
|
33
|
+
So the goal is not "one image" but "few state changes". What actually ends a
|
|
34
|
+
batch:
|
|
35
|
+
|
|
36
|
+
- **Overflowing the texture-unit pool** — pack sprites into a `TextureAtlas` and
|
|
37
|
+
prefer one large tileset over several small ones, so a screenful of sprites
|
|
38
|
+
fits inside the pool with room to spare.
|
|
39
|
+
- **Changing `blendMode`** — `setBlendMode` flushes before it touches GL state.
|
|
40
|
+
Group by blend mode where you can.
|
|
41
|
+
- **Switching batcher** — interleaving primitives (`strokeRect`, `fillRect`,
|
|
42
|
+
debug shapes) or meshes between sprites flushes the quad batcher and rebinds.
|
|
43
|
+
Draw all the sprites, then all the primitives.
|
|
44
|
+
- **Binding a custom shader** — a `ShaderEffect` on the quad batcher also turns
|
|
45
|
+
multi-texture batching *off* for the duration, dropping you back to one
|
|
46
|
+
texture per draw.
|
|
47
|
+
|
|
48
|
+
The advanced blend modes are the expensive ones: `overlay`, `difference`,
|
|
49
|
+
`hard-light`, `soft-light`, `color-dodge`, `color-burn`, `darken` and `lighten`
|
|
50
|
+
cannot be expressed as fixed-function blending, so each such draw is bracketed
|
|
51
|
+
on its own — capture the destination, redraw offscreen, composite through a
|
|
52
|
+
shader. Right for accents, wrong for hundreds of objects. `normal`, `additive`,
|
|
53
|
+
`multiply`, `screen` and `exclusion` are plain fixed-function state and cost
|
|
54
|
+
nothing extra.
|
|
55
|
+
|
|
56
|
+
## Pooling
|
|
57
|
+
|
|
58
|
+
Anything spawned frequently — bullets, particles, pickups, damage numbers —
|
|
59
|
+
should be pooled rather than allocated:
|
|
60
|
+
|
|
61
|
+
```js
|
|
62
|
+
pool.register("bullet", Bullet, true); // third arg = enable recycling
|
|
63
|
+
const b = pool.pull("bullet", x, y); // recycled: onResetEvent(x, y)
|
|
64
|
+
// fresh: new Bullet(x, y)
|
|
65
|
+
world.removeChild(b); // returns to the pool automatically
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
`register` also publishes the class as a Tiled object factory under that name,
|
|
69
|
+
so an object with a matching class or name in a `.tmx` map instantiates it. Set
|
|
70
|
+
`pool.autoRegisterTiled = false` around the call for classes that should stay
|
|
71
|
+
programmatic.
|
|
72
|
+
|
|
73
|
+
Two rules that cause subtle bugs when missed:
|
|
74
|
+
|
|
75
|
+
- **`onResetEvent` must restore everything the object's lifetime mutates** —
|
|
76
|
+
alpha, tint, scale, animation, velocity. Anything you forget carries into the
|
|
77
|
+
next use, which looks like a random visual glitch.
|
|
78
|
+
- **Pooled objects do not fire `onDestroyEvent` on removal.** Removal always
|
|
79
|
+
calls `onDeactivateEvent`, then tries `pool.push`; only when that *fails* does
|
|
80
|
+
it fall through to `destroy()`, which is what calls `onDestroyEvent`. So a
|
|
81
|
+
successfully recycled object never sees it. Pair event subscriptions with
|
|
82
|
+
`onActivateEvent` / `onDeactivateEvent` instead, or you leak handlers.
|
|
83
|
+
|
|
84
|
+
Engine classes are poolable too: `pool.pull("me.Tween", target)`.
|
|
85
|
+
|
|
86
|
+
## `scale()` is multiplicative
|
|
87
|
+
|
|
88
|
+
A pooled sprite arrives carrying its previous life's transform, and calling
|
|
89
|
+
`scale()` each frame compounds. For absolute scaling:
|
|
90
|
+
|
|
91
|
+
```js
|
|
92
|
+
sprite.currentTransform.identity();
|
|
93
|
+
sprite.currentTransform.scale(s, s, 1);
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## Culling and update cost
|
|
97
|
+
|
|
98
|
+
- `Container` recomputes `inViewport` for every child each frame against every
|
|
99
|
+
active camera, and skips both its `draw()` **and** its `update(dt)` when it is
|
|
100
|
+
off-screen. That gate is `inViewport || alwaysUpdate`, and it applies to every
|
|
101
|
+
container in every game, whichever physics you use.
|
|
102
|
+
- On top of that, the **built-in physics adapter** gates body integration and
|
|
103
|
+
narrow-phase collision on the same `inViewport || alwaysUpdate` — so an
|
|
104
|
+
off-screen body stops simulating even if something else calls its `update`.
|
|
105
|
+
The planck and matter adapters have no such gate: they step the whole world
|
|
106
|
+
regardless of the camera.
|
|
107
|
+
- Set `alwaysUpdate = true` on anything that must keep moving off-screen, and
|
|
108
|
+
accept the cost. On many objects it removes the saving entirely.
|
|
109
|
+
- `floating = true` does **not** disable culling — it moves the test into screen
|
|
110
|
+
space: a floating renderable is checked against the camera's screen rectangle
|
|
111
|
+
(`0, 0, camera.width, camera.height`) instead of the world view. That is why a
|
|
112
|
+
HUD stays put as the camera moves. `Container.draw` then draws floating
|
|
113
|
+
children unconditionally, but `update()` is still gated, so a floating object
|
|
114
|
+
parked outside the screen rectangle stops updating.
|
|
115
|
+
|
|
116
|
+
## Bake once, draw many
|
|
117
|
+
|
|
118
|
+
When you would otherwise issue hundreds of identical draws every frame, render
|
|
119
|
+
once into a `CanvasRenderTarget` and draw the result as a single sprite. This is
|
|
120
|
+
the sanctioned idiom before reaching for a custom shader — hundreds of draws
|
|
121
|
+
collapse to one.
|
|
122
|
+
|
|
123
|
+
## Instancing in 3D
|
|
124
|
+
|
|
125
|
+
`InstancedMesh` draws one mesh many times in a single call — the difference
|
|
126
|
+
between a hundred trees and a hundred thousand. glTF scenes using
|
|
127
|
+
`EXT_mesh_gpu_instancing` load as an `InstancedMesh` automatically.
|
|
128
|
+
|
|
129
|
+
It trades per-object control for the draw call: the set gets ONE depth sort key
|
|
130
|
+
and ONE ground shadow, and `removeInstance` swaps the last instance into the
|
|
131
|
+
hole so held indices go stale. Scenery yes; anything the game removes or
|
|
132
|
+
queries one at a time, usually not. See `melonjs-3d` for the decision table.
|
|
133
|
+
|
|
134
|
+
## Update loops
|
|
135
|
+
|
|
136
|
+
- `update(dt)` should **return `true` only when something changed**. Returning
|
|
137
|
+
`true` unconditionally forces redraw work every frame.
|
|
138
|
+
- Use `dt` for motion rather than assuming a fixed step — the engine already
|
|
139
|
+
paces it, and a fixed assumption breaks on high-refresh displays.
|
|
140
|
+
- Use `timer.setTimeout` / `setInterval`, which are pause-aware. `window` timers
|
|
141
|
+
keep firing behind a pause menu.
|
|
142
|
+
|
|
143
|
+
## Audio and assets
|
|
144
|
+
|
|
145
|
+
- `stream: true` on long music tracks plays through a streaming element instead
|
|
146
|
+
of decoding the whole file into memory.
|
|
147
|
+
- `pool` on an audio clip sizes the reuse pool for finished instances — it is
|
|
148
|
+
**not** a concurrency cap.
|
|
149
|
+
- `loader.unloadAll()` between large levels drops every loaded asset and
|
|
150
|
+
`destroy()`s the shader programs the loader owns — that last part is a real
|
|
151
|
+
GPU release. Images, by contrast, only lose their loader-side reference; the
|
|
152
|
+
renderer's texture cache is not purged by unloading.
|
|
153
|
+
|
|
154
|
+
## Where the costs actually are
|
|
155
|
+
|
|
156
|
+
In rough order for a typical 2D game:
|
|
157
|
+
|
|
158
|
+
1. Draw calls — fix with atlases and fewer tilesets
|
|
159
|
+
2. Overdraw from large blended sprites
|
|
160
|
+
3. Per-frame allocation — fix with pooling
|
|
161
|
+
4. `alwaysUpdate` on objects that do not need it
|
|
162
|
+
5. The engine itself, which is rarely the problem
|
|
163
|
+
|
|
164
|
+
## Symptom → cause
|
|
165
|
+
|
|
166
|
+
| symptom | cause |
|
|
167
|
+
|---|---|
|
|
168
|
+
| high draw-call count | the texture-unit pool overflows, or primitives/meshes are interleaved with sprites |
|
|
169
|
+
| draw calls jump when one effect is enabled | a custom shader on the quad batcher disables multi-texture batching |
|
|
170
|
+
| frame time spikes and GC pauses | allocating per frame instead of pooling |
|
|
171
|
+
| a recycled object looks wrong | `onResetEvent` does not restore every mutated property |
|
|
172
|
+
| sprite grows every frame | `scale()` is multiplicative — reset the transform |
|
|
173
|
+
| off-screen enemies stop moving | `update()` and built-in physics both gate on `inViewport`; set `alwaysUpdate` |
|
|
174
|
+
| a HUD element vanishes | `floating` is culled against the screen rect, and it sits outside it |
|
|
175
|
+
| everything updates even when idle | `update()` returning `true` unconditionally |
|
|
176
|
+
| memory grows with long music | missing `stream: true` |
|
|
177
|
+
| slow only on some machines | Canvas fallback — no GPU tilemap path |
|
|
178
|
+
|
|
179
|
+
## Related skills
|
|
180
|
+
|
|
181
|
+
- `melonjs-sprites-and-animation` — atlases and pooling in detail
|
|
182
|
+
- `melonjs-renderer-backends` — why performance differs per machine
|
|
183
|
+
- `melonjs-3d` — `InstancedMesh`
|
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: melonjs-physics
|
|
3
|
+
description: "Use this skill for collision, physics bodies, movement, and spatial queries in melonJS — the built-in SAT world and the planck/matter adapters. Covers bodyDef vs Body, collision types and masks, the collision callback family and their firing rules, raycast/queryAABB/querySphere, and the behaviour differences between adapters. Triggers on: Body, bodyDef, collision, collisionType, collisionMask, onCollision, onCollisionStart, onCollisionActive, raycast, queryAABB, querySphere, PlanckAdapter, MatterAdapter, gravity, velocity, applyForce, isGrounded, SAT."
|
|
4
|
+
license: MIT
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Physics and collision
|
|
8
|
+
|
|
9
|
+
> melonJS has a built-in SAT collision world and two optional rigid-body
|
|
10
|
+
> adapters. Movement, collision callbacks and spatial queries all behave
|
|
11
|
+
> differently depending on which is active — and several of the differences fail
|
|
12
|
+
> silently.
|
|
13
|
+
|
|
14
|
+
## Choosing a world
|
|
15
|
+
|
|
16
|
+
| | when |
|
|
17
|
+
|---|---|
|
|
18
|
+
| **built-in** (default) | Arcade-style: platformers, top-down games. Fast, position-based, not Newtonian. |
|
|
19
|
+
| **`@melonjs/planck-adapter`** | Full rigid-body dynamics — stacking, joints, realistic restitution. |
|
|
20
|
+
| **`@melonjs/matter-adapter`** | Same class of thing, backed by matter-js. |
|
|
21
|
+
|
|
22
|
+
An adapter is an `Application` setting, not a plugin:
|
|
23
|
+
|
|
24
|
+
```js
|
|
25
|
+
import { PlanckAdapter } from "@melonjs/planck-adapter";
|
|
26
|
+
|
|
27
|
+
const app = new Application(800, 600, {
|
|
28
|
+
parent: "screen",
|
|
29
|
+
physic: new PlanckAdapter({
|
|
30
|
+
gravity: { x: 0, y: 320 }, // pixels/s², default {x: 0, y: 320}
|
|
31
|
+
pixelsPerMeter: 32, // default 32
|
|
32
|
+
subSteps: 2, // default 1
|
|
33
|
+
}),
|
|
34
|
+
});
|
|
35
|
+
await app.init();
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
`PlanckAdapter` also takes `velocityIterations` (default `8`) and
|
|
39
|
+
`positionIterations` (default `3`). `MatterAdapter` takes a different set —
|
|
40
|
+
`gravity` (default `{x: 0, y: 1}`, matter's own convention), `subSteps` and
|
|
41
|
+
`matterEngineOptions`; it has no `pixelsPerMeter` because it already works in
|
|
42
|
+
pixels. `subSteps` is the anti-tunnelling knob when per-frame motion exceeds a
|
|
43
|
+
body radius. Pick **one** adapter per game; `physic: "none"` disables physics
|
|
44
|
+
entirely — `world.step` skips the simulation and the world behaves as a pure
|
|
45
|
+
scene graph.
|
|
46
|
+
|
|
47
|
+
`world.physic` carries the active adapter's label (`"builtin"`, `"planck"`,
|
|
48
|
+
`"matter"`, `"none"`), so game code can branch without importing the class.
|
|
49
|
+
|
|
50
|
+
## Two ways to declare a body
|
|
51
|
+
|
|
52
|
+
**`bodyDef`** — declarative, portable, works on every adapter. Prefer it.
|
|
53
|
+
|
|
54
|
+
```js
|
|
55
|
+
class Player extends Sprite {
|
|
56
|
+
constructor(x, y, settings) {
|
|
57
|
+
super(x, y, settings);
|
|
58
|
+
this.bodyDef = {
|
|
59
|
+
type: "dynamic",
|
|
60
|
+
shapes: [ /* … */ ],
|
|
61
|
+
collisionType: collision.types.PLAYER_OBJECT,
|
|
62
|
+
collisionMask: collision.types.WORLD_SHAPE | collision.types.ENEMY_OBJECT,
|
|
63
|
+
restitution: 0.2,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
The engine forwards it to the active adapter when the renderable is added with
|
|
70
|
+
`Container.addChild`, and only if that container is already attached to the root
|
|
71
|
+
world; the broadphase picks the renderable up on the next `world.update()`.
|
|
72
|
+
Calling `adapter.addBody()` yourself registers the body but leaves the
|
|
73
|
+
renderable out of the scene graph, so it integrates but never collides.
|
|
74
|
+
|
|
75
|
+
Other portable `bodyDef` fields: `density`, `frictionAir` (number or `{x, y}`),
|
|
76
|
+
`friction`, `restitution`, `gravityScale`, `maxVelocity`, `fixedRotation`,
|
|
77
|
+
`isSensor`, `userData`. Not every adapter honours every one — the built-in
|
|
78
|
+
adapter ignores `friction`, `fixedRotation` and `userData`, and maps
|
|
79
|
+
`frictionAir` onto its per-axis `body.friction` damping vector.
|
|
80
|
+
|
|
81
|
+
**`new Body(this, shape)`** — the built-in-native API. Fine, but ties the entity
|
|
82
|
+
to the built-in world.
|
|
83
|
+
|
|
84
|
+
### Per-shape filtering and triggers
|
|
85
|
+
|
|
86
|
+
A shape in `shapes` may carry its own `collisionType`, `collisionMask`,
|
|
87
|
+
`isTrigger` (default `false`) and `isActive` (default `true`). A shape can only
|
|
88
|
+
**narrow** what its body allows — the body's type/mask are checked first.
|
|
89
|
+
|
|
90
|
+
```js
|
|
91
|
+
const feet = new Rect(0, 24, 32, 8);
|
|
92
|
+
feet.collisionMask = collision.types.WORLD_SHAPE;
|
|
93
|
+
const torso = new Rect(0, 0, 32, 24);
|
|
94
|
+
torso.collisionMask = collision.types.ENEMY_OBJECT;
|
|
95
|
+
torso.isTrigger = true; // detects hits, never gets pushed by them
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
`isActive: false` removes the shape from the narrow phase *and* from raycasts
|
|
99
|
+
without shrinking the body's bounds. Honoured by the built-in and planck
|
|
100
|
+
adapters; the matter adapter filters per body and ignores them. Under planck the
|
|
101
|
+
body-wide setters (`setCollisionType` / `setCollisionMask` / `setSensor`) write
|
|
102
|
+
every fixture and so overwrite per-shape values.
|
|
103
|
+
|
|
104
|
+
For contacts reported per *shape pair* rather than per body pair, define
|
|
105
|
+
`onShapeCollisionStart` / `onShapeCollisionActive` / `onShapeCollisionEnd`.
|
|
106
|
+
Declaring at least one of them opts into shape-pair enumeration; declaring none
|
|
107
|
+
costs nothing.
|
|
108
|
+
|
|
109
|
+
## Move with forces, not by assigning position
|
|
110
|
+
|
|
111
|
+
```js
|
|
112
|
+
// ✗ the adapters overwrite this from the engine body every step
|
|
113
|
+
this.pos.x += this.speed;
|
|
114
|
+
|
|
115
|
+
// ✓ portable — works on every adapter
|
|
116
|
+
this.body.applyForce(thrustX, 0);
|
|
117
|
+
this.body.setVelocity(vx, vy);
|
|
118
|
+
|
|
119
|
+
// ✓ built-in only — `force` and `maxVel` are BuiltinAdapter Body fields
|
|
120
|
+
this.body.force.x = this.body.maxVel.x;
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
Under matter and planck, `syncFromPhysics()` copies the engine body's position
|
|
124
|
+
back onto `renderable.pos` after every step, so a direct write is simply erased
|
|
125
|
+
— no error. The built-in world integrates `pos` in place instead, so a write
|
|
126
|
+
survives but fights collision resolution and jitters. To teleport, go through
|
|
127
|
+
`adapter.setPosition(renderable, p)` so the engine body moves with it.
|
|
128
|
+
|
|
129
|
+
## Collision callbacks — which one to use
|
|
130
|
+
|
|
131
|
+
The lifecycle is `onCollisionStart` (contact begins), `onCollisionActive` (every
|
|
132
|
+
step while it persists) and `onCollisionEnd` (contact breaks). None of them are
|
|
133
|
+
defined on `Renderable` — you just declare the ones you want and the dispatcher
|
|
134
|
+
checks `typeof`. The legacy `onCollision` still exists and has a trap:
|
|
135
|
+
|
|
136
|
+
> On the built-in world, `onCollision` fires **twice per frame** for
|
|
137
|
+
> dynamic-dynamic pairs — once per outer-loop visit — and gets the raw SAT
|
|
138
|
+
> response with a fixed `a`/`b` per pair. On the adapters it is routed to their
|
|
139
|
+
> "still touching" phase and fires once per side.
|
|
140
|
+
|
|
141
|
+
The legacy dedupe idiom is `if (this !== response.a) return;`. Defining
|
|
142
|
+
`onCollisionActive` suppresses the legacy callback on that renderable (the
|
|
143
|
+
"supersedes" rule, applied per side so `a` and `b` can migrate independently),
|
|
144
|
+
and is deduped to once per pair per side per frame on every adapter.
|
|
145
|
+
|
|
146
|
+
**Return values only work on the legacy handler.** `return false` from
|
|
147
|
+
`onCollision` skips the built-in SAT push-out; what `onCollisionStart` /
|
|
148
|
+
`onCollisionActive` return is discarded. To opt a body out of the physical
|
|
149
|
+
response, set `bodyDef.isSensor` / `body.setSensor(true)`, or make the shape a
|
|
150
|
+
trigger. With no `onCollision` defined at all, push-out happens by default for
|
|
151
|
+
dynamic non-sensor bodies.
|
|
152
|
+
|
|
153
|
+
The two handler families do **not** get the same response object:
|
|
154
|
+
|
|
155
|
+
| | `onCollision` (legacy) | `onCollisionStart` / `Active` / `End` |
|
|
156
|
+
|---|---|---|
|
|
157
|
+
| `a` / `b` | fixed per pair | receiver-symmetric: `a === this`, `b === other` |
|
|
158
|
+
| overlap magnitude | `response.overlap` | `response.depth` |
|
|
159
|
+
| contact axis | `response.overlapN` / `overlapV` | `response.normal` |
|
|
160
|
+
| also carries | `aInB`, `bInA`, `indexShapeA/B`, `isTriggerContact` | `pair` (adapter-native, absent on built-in) |
|
|
161
|
+
|
|
162
|
+
On the modern response `overlap` / `overlapN` / `overlapV` are still present but
|
|
163
|
+
`@deprecated` (and `undefined` under the matter adapter) — use `depth` and
|
|
164
|
+
`normal`. `normal` is the direction the receiver must move to separate, in
|
|
165
|
+
canvas coordinates: `normal.y < -0.7` means "push me up", i.e. I landed on top
|
|
166
|
+
of `other`.
|
|
167
|
+
|
|
168
|
+
One portability wrinkle: the built-in adapter dispatches `onCollisionEnd` with
|
|
169
|
+
`undefined` as the response; the matter and planck adapters pass a real one.
|
|
170
|
+
Guard it.
|
|
171
|
+
|
|
172
|
+
## Never mutate the world during contact dispatch
|
|
173
|
+
|
|
174
|
+
Collision callbacks are dispatched from inside the physics step on every
|
|
175
|
+
adapter, and each engine has its own tolerance for being mutated there. Flag the
|
|
176
|
+
work and drain it from your `Stage.update`:
|
|
177
|
+
|
|
178
|
+
```js
|
|
179
|
+
onCollisionStart(response, other) {
|
|
180
|
+
this.pendingRemoval = true; // don't addChild / removeChildNow here
|
|
181
|
+
}
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
What actually happens per adapter:
|
|
185
|
+
|
|
186
|
+
- **built-in** — callbacks fire inline during `step()`. `Container.removeChild`
|
|
187
|
+
is deferred, so it is safe; `removeChildNow()` and `destroy()` are immediate,
|
|
188
|
+
and the detector only survives them because it re-checks `body === undefined`
|
|
189
|
+
after every user callback.
|
|
190
|
+
- **planck** — `onCollisionStart` / `onCollisionEnd` are dispatched from
|
|
191
|
+
planck's `begin-contact` / `end-contact` events, which fire *while the world
|
|
192
|
+
is locked*. Adding a renderable with a `bodyDef` there makes planck's
|
|
193
|
+
`createBody` return `null` and the adapter then throws on the null handle.
|
|
194
|
+
`onCollisionActive` is dispatched after the step and is the safe one.
|
|
195
|
+
- **matter** — callbacks come from matter's `collisionStart` / `collisionActive`
|
|
196
|
+
/ `collisionEnd` events during `Engine.update`.
|
|
197
|
+
|
|
198
|
+
## Spatial queries
|
|
199
|
+
|
|
200
|
+
`raycast` and `queryAABB` are implemented by all three adapters:
|
|
201
|
+
|
|
202
|
+
```js
|
|
203
|
+
import { Rect, Vector2d } from "melonjs";
|
|
204
|
+
|
|
205
|
+
// nearest hit only — returns null when nothing is hit
|
|
206
|
+
const hit = app.world.adapter.raycast(new Vector2d(x0, y0), new Vector2d(x1, y1));
|
|
207
|
+
// hit → { renderable, point, normal, fraction }
|
|
208
|
+
|
|
209
|
+
// takes a Rect, not a Bounds
|
|
210
|
+
const inArea = app.world.adapter.queryAABB(new Rect(x, y, w, h));
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
`querySphere(centre, radius)` (or `querySphere(sphere)`) is **built-in only**,
|
|
214
|
+
and only active under a 3D broadphase — i.e. `world.sortOn === "depth"`, which
|
|
215
|
+
`Camera3d` sets. So is `raycast3d`. Check
|
|
216
|
+
`world.adapter.capabilities.raycasts3d` before calling either. `raycast` itself
|
|
217
|
+
is capability-gated by `capabilities.raycasts`.
|
|
218
|
+
|
|
219
|
+
The legacy `collision.rayCast(line, result)` is a different API: it takes a
|
|
220
|
+
`Line`, returns an **array** of every intersecting renderable, and only exists
|
|
221
|
+
on the built-in path.
|
|
222
|
+
|
|
223
|
+
Two prerequisites that produce empty results rather than errors:
|
|
224
|
+
|
|
225
|
+
- **`isKinematic` must be `false`** for a renderable to be in the broadphase at
|
|
226
|
+
all (a `Body` sets this for you).
|
|
227
|
+
- On the **built-in** adapter, the broadphase is cleared and rebuilt inside
|
|
228
|
+
`world.update()`, so querying before the first update returns nothing.
|
|
229
|
+
|
|
230
|
+
## Built-in world quirks
|
|
231
|
+
|
|
232
|
+
These are specific to the default world and surprise people arriving from a
|
|
233
|
+
real rigid-body engine:
|
|
234
|
+
|
|
235
|
+
- **Dynamic-dynamic collision is position-based, not Newtonian.** Separation is
|
|
236
|
+
mass-proportional but the velocity response is per-body cancellation — two
|
|
237
|
+
equal-mass bodies do not exchange momentum the way you would expect.
|
|
238
|
+
- **Gravity defaults to `(0, 0.98)`** — pixels per frame², not m/s². Mutate
|
|
239
|
+
`app.world.adapter.gravity` at runtime, or pass
|
|
240
|
+
`physic: new BuiltinAdapter({ gravity })` to override it. `body.gravityScale`
|
|
241
|
+
(default `1`) scales it per body; `0` disables gravity for that body and is
|
|
242
|
+
the portable replacement for the deprecated `body.ignoreGravity`.
|
|
243
|
+
- **`applyForce(x, y)` is linear only** unless you pass the optional
|
|
244
|
+
`(pointX, pointY)` application point, which generates a torque
|
|
245
|
+
`τ = r × F` into `body.angularVelocity` via `body.pseudoInertia`.
|
|
246
|
+
`applyTorque(τ)` is the direct form. Note the rotation is visual: SAT
|
|
247
|
+
collisions stay axis-aligned.
|
|
248
|
+
- **Force accumulators reset at end-of-step** — for every body, including
|
|
249
|
+
static, paused and off-screen ones — so forces must be applied every frame to
|
|
250
|
+
persist.
|
|
251
|
+
- **`isGrounded` is flag-based, not contact-based** — the adapter returns
|
|
252
|
+
`!body.falling && !body.jumping`, flags updated by the last resolved
|
|
253
|
+
collision, not a live contact test.
|
|
254
|
+
- **`def.density` maps 1:1 to `body.mass`** (default `1`), and `def.friction` is
|
|
255
|
+
**ignored** entirely. `body.friction` is a per-axis `Vector2d` of per-step
|
|
256
|
+
velocity damping fed from `def.frictionAir`, not a surface coefficient.
|
|
257
|
+
- **`body.maxVel` defaults to `(490, 490)`** and hard-clamps velocity after
|
|
258
|
+
forces and friction. The canonical movement idiom is
|
|
259
|
+
`this.body.force.x = this.body.maxVel.x`.
|
|
260
|
+
- **Default `collisionType` is `ENEMY_OBJECT`**, and default `collisionMask` is
|
|
261
|
+
`ALL_OBJECT` — set both explicitly.
|
|
262
|
+
- **Integration is gated on `inViewport || alwaysUpdate`** — an off-screen body
|
|
263
|
+
stops simulating unless you set `alwaysUpdate = true`. It is also gated on
|
|
264
|
+
`updateWhenPaused` while the state manager is paused, and static bodies never
|
|
265
|
+
integrate.
|
|
266
|
+
- **`addBody` throws on double-registration** for a renderable that is already
|
|
267
|
+
adapter-managed.
|
|
268
|
+
|
|
269
|
+
## Porting between adapters
|
|
270
|
+
|
|
271
|
+
Same call, different magnitude — these are the ones that waste an afternoon:
|
|
272
|
+
|
|
273
|
+
- **The portable API converts for you, the native handle does not.**
|
|
274
|
+
`adapter.setVelocity` / `body.setVelocity(x, y)` are in pixels on every
|
|
275
|
+
adapter; reaching for the raw handle (`body.setLinearVelocity` on planck) puts
|
|
276
|
+
you in metres per second, scaled by `pixelsPerMeter`.
|
|
277
|
+
- **Time base differs.** Built-in `body.vel` is pixels *per frame*; planck and
|
|
278
|
+
matter integrate in seconds. The same number is ~60× off.
|
|
279
|
+
- **Force magnitudes are not comparable** between adapters; re-tune rather than
|
|
280
|
+
reuse. `applyForce` is a per-step accumulator everywhere (cleared each step,
|
|
281
|
+
so call it every frame) — `applyImpulse` is the one-shot. Matter has no native
|
|
282
|
+
impulse, so the adapter emulates it as `Δv = J / mass` and ignores the
|
|
283
|
+
application point.
|
|
284
|
+
- **`body.position` is the centroid in matter**, while `renderable.pos` is
|
|
285
|
+
top-left in melonJS. The adapter stores a per-body offset so `renderable.pos`
|
|
286
|
+
stays correct — but read `body.position` directly and you get the centroid.
|
|
287
|
+
- **Degenerate (zero-area / collinear) polygons — a Tiled polyline, a `Line` —
|
|
288
|
+
cannot be built by matter and fall back to their axis-aligned bounding box.**
|
|
289
|
+
Any other shape type throws `unsupported shape type`.
|
|
290
|
+
- **Ellipses become circles on matter**, using the average of the two radii.
|
|
291
|
+
- **`isGrounded` is capability-gated** (`capabilities.isGrounded`) and computed
|
|
292
|
+
differently per adapter: a flag read on built-in, a live scan of active
|
|
293
|
+
contacts on matter.
|
|
294
|
+
|
|
295
|
+
Adapter-specific escapes exist (`(this.body as MatterAdapter.Body).frictionAir`,
|
|
296
|
+
`adapter.matter.Constraint.create(...)`) but are not portable — flag them if you
|
|
297
|
+
use them. `adapter.capabilities` (`constraints`,
|
|
298
|
+
`continuousCollisionDetection`, `sleepingBodies`, `raycasts`, `raycasts3d`,
|
|
299
|
+
`velocityLimit`, `isGrounded`) is the portable way to branch.
|
|
300
|
+
|
|
301
|
+
## Symptom → cause
|
|
302
|
+
|
|
303
|
+
| symptom | cause |
|
|
304
|
+
|---|---|
|
|
305
|
+
| entity jitters or does not move | assigning `pos` instead of applying force |
|
|
306
|
+
| collision handler runs twice per frame | legacy `onCollision` on a dynamic pair (built-in) — use `onCollisionActive` |
|
|
307
|
+
| `return false` from a handler does nothing | return values are only honoured by legacy `onCollision` — use `isSensor` / `isTrigger` |
|
|
308
|
+
| crash or a null body when spawning from `onCollisionStart` | world mutated during contact dispatch (locked world under planck) |
|
|
309
|
+
| `raycast` / `queryAABB` finds nothing | `isKinematic` still `true`, or no `world.update` yet (built-in) |
|
|
310
|
+
| `querySphere` / `raycast3d` is not a function | 2D adapter, or built-in without a 3D broadphase (`sortOn !== "depth"`) |
|
|
311
|
+
| `response.depth` / `response.normal` are `undefined` | reading a legacy `onCollision` response — it carries `overlap` / `overlapN` |
|
|
312
|
+
| `onCollisionEnd` handler throws on `response` | built-in dispatches it with `undefined` |
|
|
313
|
+
| off-screen bodies stop simulating | built-in gating on `inViewport`; set `alwaysUpdate` |
|
|
314
|
+
| forces do nothing after switching adapter | magnitude units differ — re-tune, don't reuse numbers |
|
|
315
|
+
| `body.position` disagrees with `renderable.pos` on matter | matter stores the centroid, melonJS the top-left — the adapter offsets between them |
|
|
316
|
+
| a Tiled polyline becomes a solid box on matter | matter cannot build a zero-area polygon; the adapter falls back to its AABB |
|
|
317
|
+
|
|
318
|
+
## Related skills
|
|
319
|
+
|
|
320
|
+
- `melonjs-renderables` — `isKinematic`, which also gates the broadphase
|
|
321
|
+
- `melonjs-tilemaps` — collision shapes authored in Tiled
|