Skip to main content

Build

Melonjs 20 Migration

melonJS

Use this skill when writing melonJS code that may be based on pre-20.x knowledge, when migrating a game from melonJS 19.x or earlier, or when an API you expected does not exist. Covers the mandatory async Application.init(), the WebGL 2 baseline and WebGPU backend, renderable post effects replacing the shader property, the deprecated exports still present, and what changed again during 20.x. Triggers on: migration, upgrade, melonJS 19, me.game, me.video.init, video.renderer, renderable.shader, Compositor, CanvasTexture, me.Math, pool.pull, pool.register, world.adapter, uvOffset, deprecated.

  • New
  • v1.0.3
  • No reviews yet

Capabilities

  • Deprecated exports still present

  • The global game is not the modern shape

    Application instance as a parameter instead: Stage#onResetEvent and

  • Node and SSR

    It has no runtime dependencies as of 20.3

  • Browser support

    The published bundle targets ES2022 and uses private class members

Getting started

Full instructions

Install the skill, then ask your AI tool for the task in plain words. The full SKILL.md below shows what it covers.

Instructions: SKILL.mdv1.0.3

Migrating to melonJS 20.x

What changed in melonJS 20.x, and which older APIs are gone, deprecated, or
renamed. Read this before writing melonJS code from memory — much of what is
published about melonJS predates 20.0.

Why this skill exists: most melonJS material in circulation describes 19.x or
earlier. Code written from that knowledge looks correct and fails at runtime.
The items below are ordered by how likely they are to be reproduced from memory.

1. Application.init() is mandatory and asynchronous

Since 20.0, constructing an Application no longer initialises it.

js
// ✗ pre-20.x — the constructor called init(width, height, options) for you
const app = new Application(800, 600, { parent: "screen" });
app.world.addChild(sprite);          // added, but nothing ever renders

// ✓ 20.x
const app = new Application(800, 600, { parent: "screen" });
await app.init();                    // REQUIRED
app.world.addChild(sprite);

init() is async because acquiring a WebGPU device is async. There is no
synchronous alternative, and no automatic fallback that papers over the missing
call. Nothing that then breaks names it: the constructor still builds
app.world, so children can be added and simply never draw — no canvas is
appended, the app never subscribes to the frame tick, and app.renderer /
app.viewport stay undefined — while constructing a Sprite or Text first
throws a TypeError on the unset global game instead.

The signature changed too: 19.x took init(width, height, options), 20.x takes
none, and anything passed is ignored (settings come from the constructor).

video.init(...) no longer exists. The video module now exports only the
four renderer constants (AUTO, CANVAS, WEBGL, WEBGPU) — there is no
init on it to call. Any code shaped like me.video.init(800, 600, {...}) is
from a removed API. Build an Application and await init(). Its siblings
went with it: video.renderer, video.createCanvas() and video.getParent()
are now app.renderer, app.renderer.createCanvas() and
app.getParentElement().

init() runs once: a second call is ignored with a console warning, and after
app.destroy() it throws. A destroyed Application is final; build a new one.

Note that import * as me from "melonjs" still works, so me.Sprite style is
fine. It is the globals bootstrap that is gone, not the namespace import.

2. Post effects replaced the shader property

renderable.shader = … is deprecated since 19.2.0. Use the post-effect API:

js
// ✗ deprecated
mySprite.shader = new ShaderEffect(app.renderer, glslBody);

// ✓
mySprite.addPostEffect(new ShaderEffect(app.renderer, glslBody));

Related trap: removePostEffect() destroys the effect — and so does
assigning renderable.shader, which destroys whatever it replaces. Only an
effect carrying shared = true is spared. To turn one off temporarily, toggle
effect.enabled instead: remove-and-re-add hands you back an object whose GPU
resources have already been freed.

3. WebGL 2 is the baseline; WebGPU is the default attempt

video.AUTO now tries WebGPU → WebGL 2 → Canvas. WebGL 1 is gone.

Consequences:

  • Which backend runs is a runtime fact. Do not write code that assumes WebGL.
  • Custom shaders can carry both GLSL and WGSL in one asset, so one effect runs
    on either GPU backend.
  • Features needing a programmable pipeline are inert on Canvas and warn once
    rather than throwing.
  • Test capabilities, not the backend: renderer.shaderLanguage and
    renderer.supportsDepthBuffer replace checks on renderer.gl or
    instanceof WebGLRenderer, which answer "no" on WebGPU.
    renderer.WebGLVersion is always 2 (deprecated), and the preferWebGL1
    setting and the #webgl1 URL flag are gone.
  • A custom WebGL batcher extends WebGLBatcher (Batcher is now the
    backend-neutral base), and a custom shader on a Mesh receives model-space
    geometry: position with
    uProjectionMatrix * uViewMatrix * uModelMatrix * vec4(aVertex, 1.0) and
    tint with uTint. Sprite and post-effect shaders are unchanged.

4. Deprecated exports still present

These resolve but should not be used in new code:

deprecated since use instead
CanvasTexture 17.1.0 CanvasRenderTarget
Compositor 18.1.0 WebGLBatcher
PrimitiveCompositor 18.1.0 PrimitiveBatcher
QuadCompositor 18.1.0 QuadBatcher
Math (capitalised) 18.0.0 math (lowercase)
device.requestFullscreen / exitFullscreen 19.7.0 app.requestFullscreen() / app.exitFullscreen()
renderable.shader = … 19.2.0 addPostEffect()
Entity 18.1.0 Sprite / Renderable + a Body
loader.onload / onProgress / onError 18.2.0, removed 20.3 the LOADER_* events, or preload(assets, onloadcb)
response.overlap / overlapN / overlapV 19.5.0 response.depth / response.normal
setLineWidth() 17.3.0 the lineWidth property
pool.register / pool.pull / pool.push 18.0.0 (a console notice since 20.9) createPool() / getPool(); registerObjectClass() for a class a level names
registerTiledObjectClass / registerTiledObjectFactory 20.18.0 (no console notice) registerObjectClass / registerObjectFactory: the same functions, named for every kind of level
TMXRenderer, TMXOrthogonalRenderer, TMXIsometricRenderer, TMXHexagonalRenderer, TMXStaggeredRenderer 20.18.0 (no console notice) TileMapRenderer, OrthogonalRenderer, IsometricRenderer, HexagonalRenderer, StaggeredRenderer: the same classes
TMXTileMap, TMXTilesetGroup 20.18.0 (no console notice) TileMap, TilesetGroup: the same classes
loader.getTMX 20.18.0 (no console notice) loader.getTileMap: the same function
body.fromJSON(), a shape list given to addShape() 20.7.0 (the Body constructor form throws) bodyDef = { type, shapes: "<json asset>", id }
body.ignoreGravity 19.5.0 gravityScale = 0, or body.setGravityScale(0)
app.updateAverageDelta 20.0.0 app.lastUpdateDelta
loader.crossOrigin = … / loader.withCredentials = … 20.4.0 (assigning throws) loader.setOptions({ crossOrigin, withCredentials })
UITextButton#bitmapText 20.13.0 label

Two of these deserve emphasis:

  • Entity is still exported, so code using it compiles and runs while being
    the wrong shape for 20.x. Compose a Sprite/Renderable with a Body
    instead.
  • The capitalised Math shadows the global Math if imported carelessly.
    me.Math.random() from older docs resolves to the deprecated re-export.

5. The global game is not the modern shape

game is still exported, but since 20.0 it names the most recently
initialized Application and is undefined until the first init()
resolves — so anything reading it at module scope gets undefined. Take the
Application instance as a parameter instead: Stage#onResetEvent and
onDestroyEvent are handed it, and any renderable can reach it through
parentApp.

6. Node and SSR

melonJS imports cleanly under Node — useful for isomorphic apps and for tooling.
It has no runtime dependencies as of 20.3. Do not add polyfills for
globalThis, String.trimStart or String.trimEnd: the published bundle
targets ES2022, so every environment that can parse it already has them.

7. Browser support

The published bundle targets ES2022 and uses private class members. A browser
that predates that cannot parse the file at all — it fails at load, not when a
feature is used. Transpile if you need older browsers, and note that transpiling
handles syntax only: built-in methods need separate polyfills, which a
bundler's target setting will never add.

8. Changed again during 20.x

Code written against an early 20.x release can still trip on these:

  • world.adapter is read-only (20.14): assigning it throws a
    TypeError. app.world.setAdapter(adapter) switches adapters, rebuilding
    every body from its bodyDef.
  • renderer.uvOffset and the textureSeamFix setting are removed (20.11).
    Code that added uvOffset to a size should drop it.
  • The engine's classes are no longer in the legacy pool (20.9):
    pool.pull("Sprite"), pool.pull("Text") and the other built-in names
    throw Cannot instantiate object of type. Call the constructor, or
    getPool("text"), getPool("tween"), getPool("particle"),
    getPool("colorLayer") to recycle. pool.register(name, Class, true) no
    longer returns an instance to the pool on removal either; createPool does.
  • A container sorted on "x" or "y" re-sorts its children as they move
    (20.11, autoSort on by default). Turn autoSort off to keep an order set
    by hand. A "z" sort is unchanged.

What the shipped examples still show of the old API

The examples in this repository are the best reference for how melonJS is
assembled. Two things in them are easy to misread:

  • platformer/entities/player.ts and enemies.ts read and change
    response.overlapV in a legacy onCollision. On the built-in world that is
    not the deprecated field: the legacy handler gets the solver's own response,
    which has no normal or depth, and changing overlapV there is how a
    one-way platform or a slope changes the push-out. In a new handler
    (onCollisionStart / onCollisionActive), and on every adapter, read
    response.depth / response.normal.
  • Particle speeds tuned before 20.2 look wrong now: the particle transform fix
    changed how far a burst travels, and the examples' emitters were retuned
    upward to match. An emitter copied from an older version of an example needs
    the same.

Older copies of the examples (before 20.17) also assigned viewport.shader = …
/ sprite.shader = …, set this.z = Number.POSITIVE_INFINITY on a HUD,
extended Entity and called device.requestFullscreen(). None is current: use
addPostEffect(), addChild(hud, z), a Sprite (with a bodyDef when it
needs a body) and app.requestFullscreen().

Checklist when code "should work" but doesn't

  1. Is await app.init() there?
  2. Is the code assuming WebGL when it might be running on Canvas or WebGPU?
  3. Is it using renderable.shader = instead of addPostEffect()?
  4. Is it importing a deprecated symbol from the table above?
  5. Is it referencing a global game?
  6. Is it relying on something section 8 lists as changed during 20.x?
  • melonjs-getting-started — the correct 20.x bootstrap in full
  • melonjs-renderables — post effects, pointer events and custom draw code

Explore more skills

Browse all
This skill doesn’t include stateful context yet, instructions only. Learn about stateful skills.

Security

Loading security scan...

Reviews (0)

More from melonJS

View source →
melonjs-renderablesUse this skill when subclassing Renderable, writing a custom draw() method, handling pointer or click events on game objects, applying post effects and shaders, or controlling draw order. Covers the pos-relative draw contract, isKinematic…0 installsmelonjs-testingUse this skill to check that a melonJS game actually works before saying it does: running it in a headless browser, reading the console the engine writes, finding out which renderer the run got, driving the keyboard and the pointer,…0 installsmelonjs-ui-and-textUse this skill for HUDs, buttons, menus, options screens, dialogue panels, progress bars and on-screen text in melonJS. Covers UIBaseElement/UISpriteElement/UITextButton, UICheckbox, UISlider, ProgressBar, UIPanel (skins, layout,…0 installsmelonjs-inputUse this skill for keyboard, pointer, mouse, touch and gamepad input in melonJS. Covers the bindKey action indirection, registerPointerEvent on regions, the isKinematic requirement that silently blocks pointer events, which of several…0 installsmelonjs-performanceUse 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…0 installsmelonjs-deploymentUse this skill when packaging, shipping or scaffolding a melonJS game — starting a project with create-melonjs, building for the web, browser support and transpiling, and bundle size. For running inside a game portal, a native app, a…0 installs

Frequently asked questions about melonjs-20-migration

What does the melonjs-20-migration skill do?

Use this skill when writing melonJS code that may be based on pre-20.x knowledge, when migrating a game from melonJS 19.x or earlier, or when an API you expected does not exist. Covers the mandatory async Application.init(), the WebGL 2 baseline and WebGPU backend, renderable post effects replacing the shader property, the deprecated exports still present, and what changed again during 20.x. Triggers on: migration, upgrade, melonJS 19, me.game, me.video.init, video.renderer, renderable.shader, Compositor, CanvasTexture, me.Math, pool.pull, pool.register, world.adapter, uvOffset, deprecated. It's a reusable SKILL.md instruction set that loads into your AI coding assistant on demand, no prompt engineering, no copy-pasting every session.

How do I install the melonjs-20-migration skill?

Run `npx @skills-hub-ai/cli install melonjs-20-migration` from your terminal. The CLI writes the SKILL.md to the correct location for your AI tool (e.g. ~/.claude/skills/melonjs-20-migration/ for Claude Code or ~/.cursor/skills/ for Cursor with --target cursor) and adds it to your project's .skills.json lockfile.

Which AI tools does melonjs-20-migration work with?

melonjs-20-migration runs in Claude Code. It follows the open Agent Skills standard (SKILL.md), so the same skill works in every supported tool without modification.

Is the melonjs-20-migration skill free?

Yes. Every skill on skills-hub.ai is free and open-source. There are no premium tiers, paywalls, or usage limits. You only pay for whatever AI assistant you're already using.

How do I use melonjs-20-migration after installing it?

In Claude Code, type `/melonjs-20-migration` (or whatever slash command the skill registers) and the AI follows the skill's instructions immediately. You can also reference it by name in natural language, your AI loads the skill into context when relevant.

Can I share the melonjs-20-migration skill with my team?

Yes. Commit your project's .skills.json lockfile and teammates run `npx @skills-hub-ai/cli install` (no args) to install every skill at the exact version you pinned. Organization-scoped installs work via skills-hub.ai organizations.

Badge for your README

Show that this skill is on Skills Hub. The badge links back to this page and shows the live install count.

Install on Skills Hub badge preview
Markdown
[![Install on Skills Hub](https://skills-hub.ai/api/badges/skill/melonjs-20-migration)](https://skills-hub.ai/skills/melonjs-20-migration)
HTML
<a href="https://skills-hub.ai/skills/melonjs-20-migration"><img src="https://skills-hub.ai/api/badges/skill/melonjs-20-migration" alt="Install on Skills Hub"></a>

More options in the badge docs.