本文へ移動
cccskills
無料GitHub で公開日本語紹介

melonjs-20-migration

melonJS 19.x以前の知識を20.x向けに更新し、初期化や描画効果、廃止・非推奨APIの変更点を確認して移行時の不具合を調べられます。

原文原文の説明を見る

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)

実行スコア 未検証

インストール方法を見る

こんなときに便利

  • 19.x以前のゲームを20.xへ移行したいとき
  • 古いAPIが見つからない原因を調べたいとき
  • 非推奨の描画効果を置き換えたいとき
  • 古いサンプルコードを点検したいとき

日本語での紹介

できること

melonJS 19.x以前の知識やコードを20.x向けに見直すための変更点をまとめています。Applicationの作成後に非同期のawait app.init()が必須になったこと、video.init()がなくなったこと、video.AUTOがWebGPU、WebGL 2、Canvasを選ぶことなどを確認できます。また、renderable.shaderに代わるaddPostEffect()の使い方や、CanvasTexture、Entity、大文字のMathなど、残っていても新規コードでは避けるべきAPIを整理しています。古い資料やサンプル由来のコードが動かない場合に、初期化、描画方式、非推奨シンボルを順に点検できます。

こんなときに便利

19.x以前からゲームを更新するときや、古いチュートリアルを参考にしたコードでAPIが見つからないときに役立ちます。書いたコードがコンパイルできるのに描画されない場合や、古いAPIを新しい書き方に置き換える場合にも参照できます。

使い方の例

  • 「19.xの初期化コードをmelonJS 20.x向けに直して」
  • 「renderable.shaderを使わずにポストエフェクトを適用する方法は?」
  • 「このコードに20.xで非推奨のAPIがないか確認して」

注意点

対象はmelonJS 20.xです。古いブラウザーを対象にする場合、トランスパイルは構文を変換しますが、組み込みメソッドのポリフィルは別途必要です。

この紹介文は、公開されている SKILL.md をもとに AI(OpenAI Codex)が作成しました。正確な仕様は下の原文を確認してください。

含まれるファイル(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 / 1000 文字

このフォームは reCAPTCHA で保護されており、Google のプライバシーポリシーと利用規約が適用されます。

同じリポジトリのスキル

melonjs

無料概要あり

melonJSを使ったゲーム制作で、目的に合う専門ガイドを選ぶための入口です。初期化から描画、入力、物理演算、音声、2D・3D機能まで案内します。

  • melonJSで作る内容に合うガイドを探したいとき
  • 新しいゲームの初期化手順を知りたいとき
  • 3Dやモデル読み込みの参照先を探したいとき
melonjs/melonJS6,4292026年10月29日 更新

melonjs-3d

無料概要あり

melonJSの3D・2.5Dゲーム向けに、カメラ、メッシュ、ライト、奥行き順、透明表現やフォグの設定と座標系の注意点を確認できます。

  • 3Dカメラをステージに設定したいとき
  • メッシュやビルボードを配置したいとき
  • 奥行き順や透明表現を調整したいとき
melonjs/melonJS6,4292026年10月29日 更新

melonjs-3d-assets

無料概要あり

melonJSでglTF・GLBやOBJ・MTLの3Dモデルを読み込み、マテリアルやライト、アニメーション、影、インスタンスの扱い方を確認できます。

  • glTF・GLBのシーンを読み込みたいとき
  • OBJモデルとMTL素材を使いたいとき
  • モデルの向きや大きさを調整したいとき
melonjs/melonJS6,4292026年10月29日 更新

melonjs-audio

無料概要あり

melonJSで効果音やBGMを読み込み、再生・停止・音量調整するほか、位置に応じた音や音声合成、ミックス全体へのエフェクト設定を扱うスキルです。

  • 効果音とBGMを読み込みたいとき
  • ゲーム内の位置に応じて音を鳴らしたいとき
  • 音声ファイルなしで短い音を作りたいとき
melonjs/melonJS6,4292026年10月29日 更新

melonjs-camera-and-drawing

無料概要あり

melonJSのカメラ追従や画面効果、座標変換、図形描画を実装する際の要点を確認できます。描画のクリッピングやCanvasへの焼き込み、ピクセルの読み出しも扱います。

  • プレイヤーを追うカメラの範囲を設定したいとき
  • ワールド座標と画面座標を変換したいとき
  • 独自描画に図形やグラデーションを使いたいとき
melonjs/melonJS6,4292026年10月29日 更新

melonjs-deployment

無料概要あり

melonJSゲームのWeb向けビルドやネイティブアプリ化、ミニゲーム配信に向けた準備を進め、ブラウザー対応や容量の注意点も確認できます。

  • 配布用のゲームプロジェクトを作りたいとき
  • iOSやAndroid向けにアプリ化したいとき
  • 古いブラウザーへの対応を検討したいとき
melonjs/melonJS6,4292026年10月29日 更新

melonjs のスキルをすべて見る

このスキルの問題を報告する