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

melonjs-plugins

melonJSのプラグインや物理アダプターの導入方法を整理し、デバッグ表示やSpine、圧縮マップ対応、自作プラグインの登録と拡張を案内します。

原文原文の説明を見る

Use this skill when adding a melonJS plugin or adapter — the debug panel, Spine skeletal animation, compressed Tiled map support, Capacitor packaging — or when writing your own plugin. Covers plugin.register and its version gate, plugin.cache, plugin.patch, and why physics adapters are not plugins. Triggers on: plugin, plugin.register, plugin.cache, plugin.get, plugin.patch, BasePlugin, debug-plugin, DebugPanelPlugin, SpinePlugin, TiledInflatePlugin, CapacitorPlugin, adapter, custom plugin, plugin version mismatch, already registered.

melonjs/melonJSスター 6,429(GitHub 6,429 + cccskills 0)

実行スコア 未検証

インストール方法を見る

こんなときに便利

  • デバッグパネルを登録したいとき
  • Spineや圧縮マップを導入したいとき
  • 物理アダプターの選び方を確認したいとき
  • melonJS用プラグインを自作したいとき

日本語での紹介

できること

melonJSでプラグインを登録し、エンジン機能を拡張する方法を確認できます。plugin.registerの呼び出し時期やバージョン判定、インスタンスの取得、既存メソッドへのパッチ適用を扱います。デバッグパネル、Spineアニメーション、圧縮されたTiledマップ、Capacitor連携などの公式プラグインの用途も紹介します。物理アダプターはプラグインではなく、Applicationの設定として初期化前に選ぶ仕組みだと区別できます。

こんなときに便利

プラグインの登録エラーやバージョン不一致を解決したいとき、用途に合う公式プラグインを選びたいときに役立ちます。エンジン全体に処理を追加する自作プラグインの設計にも使えます。

使い方の例

  • 「デバッグパネルをゲームに追加する手順を教えて」
  • 「圧縮されたTiledマップを読み込むために必要なものは?」
  • 「melonJSのメソッドを拡張するプラグインを書きたい」

注意点

プラグイン登録はapp.init()の完了後に行います。PlanckやMatterなどの物理アダプターは初期化時に選び、ゲームごとに1つを使います。

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

含まれるファイル(1)

  • SKILL.md8.0 KB

SKILL.md(原文)

インストールする前に、エージェントに与えられる指示の中身を確認できます。

Plugins and adapters

Two different mechanisms

This trips people up, so it is worth stating first:

how it is installed
Pluginsplugin.register(Class, name?, ...args) — after await app.init()
Physics adaptersan Application setting (physic:), before init()
// the adapter is chosen at construction …
const app = new Application(800, 600, {
    parent: "screen",
    physic: new PlanckAdapter({ gravity, pixelsPerMeter }),
});

// … the plugin is registered once the renderer exists
await app.init();
plugin.register(DebugPanelPlugin, "debugPanel");

register in detail

plugin.register(PluginClass, "name", ...constructorArgs);
plugin.cache.name;              // the instance
plugin.get(PluginClass);        // by class — or by registered name string
  • The name is optional — it falls back to the class name.
  • The registry is global, not per-application. It is a module-level object, so registering the same name twice throws plugin <name> already registered. A plugin instance does hold an app reference, but it defaults to game — whichever Application most recently finished init(), since that is where game is assigned. On a multi-application page, pass the app explicitly through the constructor args: plugin.register(DebugPanelPlugin, "debugPanel", input.KEY.S, myApp).
  • BasePlugin.version is a floor, not an identity. It declares the minimum melonJS version the plugin needs, and register throws Plugin version mismatch, expected: <floor>, got: <engine> when the running engine is older. That gate is the real enforcement — a peer-dependency range only warns at install time, and not at all for CDN or pre-bundled use. If you see that error, upgrade the engine or pin an older plugin. The check runs after the instance is constructed, so a plugin whose constructor has side effects will already have run them when it throws.

Register after await app.init(): a plugin binds to an Application and reads renderer and frame state that does not exist before init.

The official plugins

@melonjs/debug-plugin

An in-game panel — frame time, draw and object counts — plus toggles for hitbox/bounding-box overlays, velocity vectors and quadtree visualisation. The first thing to reach for when something is slow or a collision is not landing where you expect.

import { DebugPanelPlugin } from "@melonjs/debug-plugin";
plugin.register(DebugPanelPlugin, "debugPanel");   // default toggle key: S

@melonjs/tiled-inflate-plugin

Required, not optional, for Tiled maps using gzip, zlib or zstd layer compression. It installs the inflate hook TMXUtils calls; without it a compressed .tmx fails to parse — a map that opens fine in Tiled and refuses to load in melonJS is nearly always this.

import { TiledInflatePlugin } from "@melonjs/tiled-inflate-plugin";
plugin.register(TiledInflatePlugin);

@melonjs/spine-plugin

Spine 4.x skeletal animation as a melonJS renderable, on all three backends. This is the answer for deforming animated characters — glTF import does not read vertex skinning. It also registers a Tiled object class, so Spine skeletons can be placed from a map.

@melonjs/capacitor-plugin

Bridges Capacitor's native lifecycle and hardware-back events into the engine:

import { CapacitorPlugin } from "@melonjs/capacitor-plugin";
plugin.register(CapacitorPlugin, "capacitor", options);
// plugin.cache.capacitor.teardown()  — detach every listener

It also exports helpers usable on their own: onBackButton, bindStageBack, lockOrientation / unlockOrientation, hideSplash. See melonjs-deployment for the wider packaging picture.

Physics adapters

@melonjs/planck-adapter and @melonjs/matter-adapter swap the physics world wholesale. Pick one per game. The portable surface — the declarative renderable.bodyDef, world.adapter.queryAABB(rect) and world.adapter.raycast(from, to) — works unchanged across the built-in world and both adapters, so entity code does not have to branch.

Two queries are not portable: querySphere and raycast3d exist only on the built-in adapter (planck and matter are 2D-only and deliberately omit them). queryAABB is the one region query every adapter must implement, so call the others optionally — app.world.adapter.querySphere?.(center, radius). For rays there is a real flag: app.world.adapter.capabilities.raycasts3d.

Behaviour genuinely differs: velocity units, force magnitudes and where a body's position is measured from all change. See melonjs-physics.

Writing your own

There is no init() lifecycle hook — the constructor is where setup goes, and register instantiates it for you.

import { plugin, event } from "melonjs";

class MyPlugin extends plugin.BasePlugin {
    constructor(app = undefined) {
        super(app);              // stores it as this.app
        this.version = "20.0.0"; // MINIMUM engine version this needs
        event.on(event.GAME_UPDATE, () => { /* … */ });
    }
}

plugin.register(MyPlugin, "myPlugin");

this.version defaults to the running engine version, which means it always passes — set it deliberately to the oldest version you actually support.

To wrap an existing engine method, plugin.patch keeps the original reachable as this._patched():

plugin.patch(app, "update", function (time) {
    const result = this._patched(time);
    return result;
});

patch takes a class or an instance: given a constructor it patches the prototype (that is how the debug plugin decorates Renderable.postDraw), given a plain object it patches that object. this._patched is only bound for the synchronous duration of your replacement — it is set before the call and nulled straight after — so call it inline, never after an await.

plugin.patch(Renderable, "postDraw", function (renderer) {
    this._patched(renderer);
    // draw an overlay on top of every renderable
});

A plugin is the right shape when you need to augment engine classes or hook the engine lifecycle globally. For anything that is just game code, a Renderable or a Stage is simpler and easier to test.

Symptom → cause

symptomcause
plugin <name> already registeredthe registry is global; registered twice, often across hot reloads
Plugin version mismatchthe plugin's version floor is above the running engine
Plugin should extend the BasePlugin Class !the class does not extend plugin.BasePlugin
the panel reports another app's numbersapp defaulted to game, the last Application to finish init()
world.adapter.querySphere is not a functionbuilt-in adapter only; planck and matter are 2D-only
a Tiled map opens in Tiled but not melonJScompressed layers, tiled-inflate plugin missing
plugin setup never runssetup written in an init() method — there is no such hook
plugin.register for an adapter does nothingadapters are a construction setting, not a plugin
physics behaves differently after adding an adapterexpected — units and force scales differ; re-tune

Related skills

  • melonjs-physics — the adapters and their behavioural differences
  • melonjs-tilemaps — where the inflate plugin becomes mandatory
  • melonjs-performance — using the debug panel to measure
  • melonjs-deployment — Capacitor and native packaging
  • melonjs-3d-assets — why skeletal characters go through Spine

レビュー

まだレビューはありません。使ってみた感想をお寄せください。

コメント

ログインなしで書き込めます。使ってみた感想、質問、動かなかった環境などを気軽にどうぞ。

まだコメントはありません。最初のコメントを書いてみませんか。

送信するとすぐに公開されます。メールアドレスや電話番号などの個人情報は書かないでください。URL は 2 つまでです。

0 / 1000 文字

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

同じリポジトリのスキル

melonjs

無料概要あり

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

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

melonjs-20-migration

無料概要あり

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

  • 19.x以前のゲームを20.xへ移行したいとき
  • 古いAPIが見つからない原因を調べたいとき
  • 非推奨の描画効果を置き換えたいとき
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 のスキルをすべて見る

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