-
-
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.
- Application : starting a game is now two steps — construct the
Application, thenawait app.init()— and callinginit()is mandatory, not optional.init()is asynchronous because a WebGPU device cannot be acquired synchronously; it still resolves without suspending on the Canvas and WebGL backends. Renderer failures surface as a rejection ofinit(), no longer as a constructor throw. This applies just as much to code already usingnew Application(...)on 19.x — constructing the instance no longer builds the renderer or appends the canvas; addawait app.init()right after construction, or the application displays nothing. - Application :
app.destroy()is now terminal — a destroyed Application cannot be re-initialized (init()rejects afterwards); construct a new instance to start again. A repeatedinit()on a live app is a warned no-op. - Application : the pre-created bootstrap application and the
legacysetting are removed. The exportedme.gamenow names the most recently initializedApplication— it never points at a half-built app, and it isundefineduntil the firstinit()resolves. Hold your own reference (const app = new Application(...)) instead of reaching for the global. - Renderer : custom renderer classes gained an argument-less async
init()lifecycle hook thatApplication#initawaits after construction. Classes extendingRendererneed no changes (the base class resolves immediately); a custom renderer that already had its owninit()method should expect the engine to call it with no arguments. - video :
video.init()is removed (deprecated since 18.3.0). Use theApplicationentry point:
// before
if (!me.video.init(640, 480, { parent: "screen", renderer: me.video.AUTO })) {
alert("Your browser does not support HTML5 canvas.");
return;
}
// after
try {
const app = new me.Application(640, 480, { parent: "screen", renderer: me.video.AUTO });
await app.init(); // mandatory — builds the renderer and appends the canvas
} catch {
alert("Your browser does not support HTML5 canvas.");
return;
}Note the failure mode changed: video.init() returned false when the canvas could not be created, whereas app.init() rejects. catch the rejection if you were relying on the boolean.
- video :
video.rendereris removed (deprecated since 18.3.0). Useapp.renderer— orme.game.rendererwhere only the global is in reach. - video :
video.createCanvas()is removed (deprecated since 19.7.0). Useapp.renderer.createCanvas(width, height, [returnOffscreenCanvas])— the renderer instance reached throughApplication#rendereris the supported entry point.
// before
const canvas = me.video.createCanvas(64, 64);
// after
const canvas = app.renderer.createCanvas(64, 64);- video :
video.getParent()is removed (deprecated since 18.3.0). Useapp.getParentElement(). - 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.WEBGLmakesapp.init()reject. 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. - 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 - Batcher : each batcher now owns an immutable Vertex Array Object, built once in
init()— the vertex attribute layout is frozen from that point on, a batcher switch is a singlebindVertexArray, and steady-state frames issue no attribute-specification calls at all. Custom batchers that subclassBatcher/QuadBatcherand chain tosuper.init()/super.bind()need no changes. Two things to be aware of if you wrote lower-level code: callinggl.vertexAttribPointer/enable/disableVertexAttribArrayyourself now mutates the bound batcher's frozen vertex state rather than global GL state, andaddAttribute()throws once the vertex state exists (declare your layout before/insideinit()). - custom shaders : a shader hosted by a built-in batcher must declare that batcher's attributes first, in the batcher's layout order — attribute locations are bound in vertex-source declaration order and the vertex state is frozen against the default shader's mapping. Shaders generated by
ShaderEffectalready comply, so ordinary effects are unaffected; a rawGLShaderthat declares them out of order will read the wrong vertex data, and logs a console warning identifying the mismatch.GLShader.setVertexAttributes()is still public but is no longer called by the engine.
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