-
-
Notifications
You must be signed in to change notification settings - Fork 662
Upgrade Guide
This page list the public APIs change between melonJS release. To be noted that we always provide backward compatibility as much as possible by providing method wrapping on public deprecated API(s).
Important: melonJS uses Semantic Versioning, which means that only MAJOR version (e.g. moving from 9.x.x to 10.x.x) will introduce breaking API changes. For any other MINOR or PATCH version, melonJS API provides seamless upgrade.
Note: As the initial 10.0 version marks the release of melonJS2, that is now fully ES6 compliant, all deprecated API and method from previous "legacy" versions (9.x and lower) have been removed. If you are looking for the changelog for the legacy version see here, see as well here for a dedicated upgrading guide from Legacy version of melonJS to melonJS 2
Note: To keep our code base as clean as possible, deprecated API are being kept until the next N+2 version, for example when publishing a new major 17.x version of melonJS, all deprecated API in version 14.x and before will be removed.
- video : the WebGL renderer is now WebGL 2 only — the WebGL 1 fallback path has been removed (#1509). On the rare devices without WebGL 2 support,
renderer: video.AUTOnow falls back to the Canvas renderer, and an explicitrenderer: video.WEBGLthrows at construction time. No action needed for the overwhelming majority of devices (WebGL 2 has been universal for years, including Safari); if you must target WebGL-1-only hardware, stay on the 19.x line or use the Canvas renderer. - shaders : no changes needed — custom
ShaderEffectbodies and rawGLShadersources written in GLSL ES 1.00 compile unchanged on WebGL 2 contexts (this is spec-guaranteed, and how every WebGL 2 install already ran them). - Application : the
preferWebGL1setting and the#webgl1URL flag are removed (#webgland#webgl2are synonyms) - device :
isWebGLSupported()now probes for a WebGL 2 context, so it always agrees with what renderer construction actually requests - Renderer :
WebGLVersionis deprecated and always returns2;renderer.typeis always"WebGL2"for the WebGL renderer - behavior corrections on hardware that previously fell back to WebGL 1:
repeatwrap now genuinely tiles non-power-of-two textures (was silently clamped with a console warning), the"darken"/"lighten"blend modes use true MIN/MAX blend equations (were silently downgraded to"normal"), andcreatePattern()accepts non-power-of-two sources (previously threw) - custom renderer authors : TMX GPU tilemap eligibility is now advertised via the
renderer.supportsShaderTileLayerscapability flag on the baseRendererclass (replaces the internal WebGL-version check)
no breaking API changes — two behavior corrections worth knowing about:
- Application : the game canvas now defaults to
display: block(the browser'sinlinedefault created a baseline gap that could feed a canvas-growth loop under auto-scaling, #1231); set any inlinedisplaystyle on the canvas to keep your own value - Sprite : video sprites now genuinely pause on
state.pause()— this was always the documented behavior, but the internal listener never fired
- video :
video.createCanvas(width, height, returnOffscreenCanvas)is now deprecated — use the newRenderer.createCanvas(width, height, returnOffscreenCanvas)static method instead. The old call still works (with a console deprecation warning) but forwards to the renderer-side API. Centralizing canvas allocation onRenderermakes it reachable without an active renderer instance (e.g. from a Mesh constructor) and decouples it from the deprecatingvideonamespace.
- Light2d : now centered on its
pos(anchorPoint = (0.5, 0.5)) to matchSpriteandEllipse(x, y, w, h)conventions — constructorx/yandlight.posdenote the light's center, not the bounding-box top-left. Existing call sites that passed top-left coordinates need to shift by the radii:new Light2d(x, y, r)→new Light2d(x + r, y + r, r). Code usinglight.centerOn(x, y)is unaffected. Transforms (scale,rotate) now pivot around the visual center.
- Renderable :
currentTransformis now aMatrix3d(wasMatrix2d) — code accessingval[6]/val[7]for tx/ty must useval[12]/val[13] - Renderable :
rotate(angle, axis)now accepts an optionalaxisparameter (defaults to Z axis) - Renderable :
scale(x, y, z)now accepts an optionalzparameter (defaults to 1) - Matrix3d :
scale(x, y, z)defaultzchanged from0to1 - Matrix3d :
rotate(angle, axis)axis parameter now optional, defaults to Z axis - Matrix3d :
multiply(m)now accepts bothMatrix3dandMatrix2d - Matrix3d :
rotate()returnsthisinstead ofnullon zero-length axis - Matrix2d :
fromMat3d()now extracts translation from indices[12],[13](was[8],[9]) - Text :
draw()no longer acceptstext,x,yparameters — standalone draw removed (deprecated since 10.6.0) - BitmapText :
draw()no longer acceptstext,x,yparameters — standalone draw removed (deprecated since 10.6.0) - Text :
measureText()no longer takes arendererparameter (was unused) - UITextButton : settings
backgroundColorandhoverColorremoved — usehoverOffColorandhoverOnColor - Tween : no longer adds itself to
game.world— uses event-based lifecycle (TICK,GAME_AFTER_UPDATE,STATE_PAUSE,STATE_RESUME,GAME_RESET). Public API (to(),start(),stop(),chain(), etc.) is unchanged.isPersistentandupdateWhenPausedstill supported. - Application :
depthTestsetting removed — GPU depth sorting is incompatible with 2D alpha blending. Depth testing remains available internally for 3D mesh rendering only (drawMesh).
- Application :
new Application(width, height, options)is now the recommended entry point.video.init(),video.renderer,video.getParent(), anddevice.onReady()are deprecated — useApplicationdirectly and access the renderer viaapp.renderer - Stage :
onResetEvent(app, ...args)andonDestroyEvent(app)now receive the Application instance as first parameter - Container : default dimensions are now
Infinity(no intrinsic size) — thegame.viewportdependency has been removed
no breaking API changes
- Renderer :
Compositor,QuadCompositor, andPrimitiveCompositorare now deprecated in favor ofBatcher,QuadBatcher, andPrimitiveBatcher
- chore : deprecated classes and methods from version 15 and lower have been removed (
Texture,DraggableEntity,DroptargetEntity,getScreenCanvas,getScreenContext,GUI_Object,getWidth,getHeight)
- loader : the
nocache,crossOriginandwithCredentialsloader options, now have to be set using thesetOptions()method, for example :me.loader.setOptions({ crossOrigin : "anonymous" });
no breaking API changes
- UI:
GUI_Objectis now deprecated and replaced by two new classes,UISpriteElementandUITextButton - Text :
drawStroke()is now deprecated in favour of thelineWidthproperty, which when set to a value greater than 0 will automatically stroke the text
no breaking API changes
- device: as part of
devicerefactoring to a proper ES6 syntax, the previousdevice.isFullScreenproperty has been changed into adevice.isFullScreen()function - device: deprecated function
device.turnOnPointerLockanddevice.turnOffPointerLocksince version 10.3 have been removed; please useinput.requestPointerLock()orinput.exitPointerLock() - Physic: when applying a force, melonJS will now automatically reset the remaining force to 0 at the end of the update loop.
- Core:
utils.stringhelper trim functions have been removed in favour to their native es10 equivalent (String.trimLeftandString.trimRight)
- Renderable: the Light2d constructor now takes an additional parameter (
x, y, radiusX, [radiusY], [color], [intensity])allowing to create elliptical shaped lights
no breaking API changes
- Renderable:
DraggableEntityandDroptargetEntityhave been renamed toDraggableandDropTarget
- Renderer: the
video.renderer.Textureclass is now directly available asTextureAtlas
- Input:
device.turnOnPointerLock()anddevice.turnOffPointerLock()have been replaced respectively byinput.requestPointerLock()andinput.exitPointerLock(), and updated to the latest 2.0 specs
- Core :
me.timer.lastUpdatehas been moved tome.game.lastUpdate - Physic : physic body update and collision check is now automatically done through the world simulation update loop (see the specific wiki entry on upgrading to melonJS 2)
- Event : minPubSub event based implementation has been replaced by a nodeJS event emitter based implementation, with
me.event.publish(),me.event.subscribe()andme.event.unsubscribe()being replaced respectively byme.event.emit(),me.event.on()(orme.event.once()) andme.event.off().