본문으로 건너뛰기
cccskills
무료GitHub에 공개

melonjs-20-migration

Update older melonJS code for version 20.x. Review the asynchronous Application setup, renderer changes, post-effect API, and deprecated exports so you can identify outdated patterns when migrating or debugging expected APIs.

한국어 요약은 준비 중입니다. 영어 요약을 표시하고 있습니다.

원문원문 설명 보기

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, and the deprecated exports still present. Triggers on: migration, upgrade, melonJS 19, me.game, me.video.init, renderable.shader, Compositor, CanvasTexture, me.Math, deprecated.

melonjs/melonJS스타 6,429(GitHub 6,429 + cccskills 0)

실행 점수 미검증

설치 방법 보기

이럴 때 유용합니다

  • Migrating a game from melonJS 19.x
  • Checking why an older API is missing
  • Replacing deprecated shader assignments
  • Reviewing renderer changes in version 20

포함된 파일(1)

  • SKILL.md7.4 KB

SKILL.md(원문)

설치하기 전에 에이전트에게 전달되는 지시 내용을 확인할 수 있습니다.

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.

// ✗ 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().

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:

// ✗ 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.

4. Deprecated exports still present

These resolve but should not be used in new code:

deprecatedsinceuse instead
CanvasTexture17.1.0CanvasRenderTarget
Compositor18.1.0WebGLBatcher
PrimitiveCompositor18.1.0PrimitiveBatcher
QuadCompositor18.1.0QuadBatcher
Math (capitalised)18.0.0math (lowercase)
device.requestFullscreen / exitFullscreen19.7.0app.requestFullscreen() / app.exitFullscreen()
renderable.shader = …19.2.0addPostEffect()
Entity18.1.0Sprite / Renderable + a Body
loader.onload / onProgress / onError18.2.0, removed 20.3the LOADER_* events, or preload(assets, onloadcb)
response.overlap / overlapN / overlapV—response.depth / response.normal
setLineWidth()17.3.0the lineWidth property

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.

The shipped examples are not all current

The examples in this repository are the best reference for how melonJS is assembled, but a few contain stale comments or legacy calls. Do not learn these from them:

  • webgpu/ has a comment claiming "video.AUTO never selects the WebGPU backend". That is pre-20 leftover — AUTO tries WebGPU first. The code is right; the comment is wrong.
  • Several examples assign viewport.shader = … / sprite.shader = …, which is deprecated. addPostEffect() is current.
  • Five files set this.z = Number.POSITIVE_INFINITY on a HUD. That property does not exist; those HUDs draw on top only because they are added last.
  • platformer/entities/player.ts reads response.overlapV, the deprecated field. Use response.depth / response.normal.
  • Particle speeds tuned before 20.2 look wrong now: the particle transform fix changed how far a burst travels, and emitters were retuned upward to match.

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?

Related skills

  • melonjs-getting-started — the correct 20.x bootstrap in full
  • melonjs-renderables — post effects, pointer events and custom draw code

리뷰

아직 리뷰가 없습니다. 사용해 본 소감을 남겨 주세요.

댓글

로그인 없이 쓸 수 있습니다. 사용 후기, 질문, 작동하지 않은 환경 등을 편하게 남겨 주세요.

아직 댓글이 없습니다. 첫 댓글을 남겨 보세요.

보내면 바로 공개됩니다. 이메일 주소나 전화번호 같은 개인 정보는 쓰지 마세요. URL은 2개까지입니다.

0 / 1,000자

이 양식은 reCAPTCHA로 보호되며 Google 개인정보처리방침 및 서비스 약관이 적용됩니다.

같은 저장소의 스킬

melonjs

무료

Use this entry point to find the melonJS guide for a game development task, from application setup and scenes to sprites, input, physics, audio, and 3D. It also points to companion packages and the API index when the guides do not cover a need.

한국어 요약은 준비 중입니다. 영어 요약을 표시하고 있습니다.

  • Choose a guide for a melonJS game task
  • Find the right setup steps for a new game
  • Locate guidance for a 3D scene or imported model
melonjs/melonJS6.4천2026년 10월 29일 업데이트

Build 3D or 2.5D scenes in melonJS with cameras, meshes, billboards, lights, shadows, and depth sorting. This guide explains the engine’s Y-down and +Z-forward coordinates, camera setup, transparency, and fog, and identifies features that require a GPU renderer instead of the Canvas fallback.

한국어 요약은 준비 중입니다. 영어 요약을 표시하고 있습니다.

  • Setting up a Camera3d for a game stage
  • Placing meshes, billboards, or repeated instances
  • Fixing depth order or transparency in a 3D scene
melonjs/melonJS6.4천2026년 10월 29일 업데이트

Load glTF, GLB, or OBJ/MTL assets into melonJS and understand how their materials, lights, animations, shadows, and instances are handled. The guide explains loader options and common format limitations so you can configure scenes and diagnose missing or incorrectly rendered asset features.

한국어 요약은 준비 중입니다. 영어 요약을 표시하고 있습니다.

  • Loading a glTF or GLB scene into a melonJS level
  • Adding a static OBJ model with its MTL material
  • Checking why imported materials or lights look different
melonjs/melonJS6.4천2026년 10월 29일 업데이트

Manage sound in melonJS games: load audio, play effects and looping background tracks, control volume, and place sounds in the game world. It also covers generated tones and noise, whole-mix effects, and common causes of silent playback.

한국어 요약은 준비 중입니다. 영어 요약을 표시하고 있습니다.

  • Loading sound files and choosing supported audio formats
  • Playing sound effects and looping background music
  • Positioning sounds around a player or game object
melonjs/melonJS6.4천2026년 10월 29일 업데이트

Use this skill to control melonJS cameras and draw shapes, lines, and gradients. It covers target following, camera bounds and effects, coordinate conversion, clipping, rendering into a canvas target, and reading rendered pixels for images or data.

한국어 요약은 준비 중입니다. 영어 요약을 표시하고 있습니다.

  • Making a camera follow a player within world bounds
  • Converting pointer or 3D positions to screen coordinates
  • Drawing shapes or gradients in a custom draw method
melonjs/melonJS6.4천2026년 10월 29일 업데이트

Prepare a melonJS game for web builds, native app packaging, or mini-game platforms. The guide covers project scaffolding, browser syntax support, transpiling, asset-loading constraints, and practical bundle-size considerations.

한국어 요약은 준비 중입니다. 영어 요약을 표시하고 있습니다.

  • Scaffolding a new melonJS project
  • Preparing a game for iOS or Android packaging
  • Checking support for older browsers
melonjs/melonJS6.4천2026년 10월 29일 업데이트

melonjs의 스킬 모두 보기

이 스킬의 문제 신고