/melonjs:melonjs-pluginsfrom melonjs
Registers and manages melonJS plugins including debug panel, Spine animation, Tiled maps, touch controls, A* pathfinding, and Capacitor packaging. Covers plugin.register, version gating, caching, patching, and physics adapter distinction.
Ships in melonjs. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
This trips people up, so it is worth stating first:
| how it is installed | |
|---|---|
| Plugins | plugin.register(Class, name?, ...args) — after await app.init() |
| Physics adapters | an Application setting (physic:), before init(); or app.world.setAdapter() on a running game |
// the adapter is chosen at construction …
const app = new Application(800, 600, {
parent: "screen",
physic: await PlanckAdapter.create({ gravity, pixelsPerMeter }),
});
// … the plugin is registered once the renderer exists
await app.init();
plugin.register(DebugPanelPlugin, "debugPanel");
register in detailplugin.register(PluginClass, "name", ...constructorArgs);
plugin.cache.name; // the instance
plugin.get(PluginClass); // by class — or by registered name string
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.
@melonjs/debug-pluginAn 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-pluginRequired, 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-pluginSpine 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.
import Spine, { SpinePlugin } from "@melonjs/spine-plugin";
await app.init();
plugin.register(SpinePlugin); // after init: it reads app.renderer
// preloaded as { name: "hero.atlas", type: "spine", src: … }, and the same for
// "hero.json" (a binary "hero.skel" also goes in jsonFile)
const hero = new Spine(100, 100, { atlasFile: "hero.atlas", jsonFile: "hero.json" });
Register it after await app.init() like any plugin: its constructor builds
an asset manager on the application's renderer, which does not exist before.
@melonjs/gamepad-pluginOn-screen touch controls, reported as a gamepad: one or two sticks and any
number of buttons, drawn over the game and read by the engine as a pad in a
gamepad slot. The game's bindGamepad bindings drive it unchanged, so one set
of bindings covers a real pad and a touch screen.
import { GamepadPlugin } from "@melonjs/gamepad-plugin";
plugin.register(GamepadPlugin, "gamepad", {
buttons: [{ label: "A" }, { label: "B" }],
});
// plugin.cache.gamepad.visible — showing, to word prompts ("tap" or a key)
Shown on touch screens by default (enabled), hidden while a real pad is in
use. The left stick also presses the D-pad; a button can press a key instead
of a pad button. Since 1.1 a stick or button can be floating (shows up
under the finger anywhere in its area), hideAtRest (drawn only while
held), and a stick can take a tap (a quick touch that does not steer presses
a key or button) — so the mobile layouts, two thumbs or one thumb with
tap-to-act, need no code of their own. Since 1.2 a skin texture atlas draws
them from the game's own art (base / thumb regions on a stick, region /
pressed on a button). It needs melonJS 20.12 or later. See melonjs-input
for the bindings, the layouts and the overlap rules.
@melonjs/pathfinding-pluginA* on a grid of open and solid cells, each with a weight to cross. The grid is the part to get right; the search is one call:
import { Grid } from "@melonjs/pathfinding-plugin";
// a layer of walls: a tile makes its cell solid (a tile's `weight` property, or attribute, sets its weight)
const grid = Grid.fromTileLayer(app.world.getChildByName("walls")[0]);
// a floor layer: decide from the tile instead
Grid.fromTileLayer(floor, { solid: (tile) => tile === null || isWall(tile) });
// or the level's collision shapes (WORLD_SHAPE bodies, a Tiled collision layer)
Grid.fromBodies(app.world, { cols, rows, tileWidth, tileHeight });
grid.diagonalMode = "onlyIfNoObstacles"; // never cut a corner past a wall
grid.getIdPath(fromCell, toCell); // cells (Vector2d, x the column)
grid.getPointPath(fromCell, toCell); // world points (cell centre + grid.offset)
const { path, found } = grid.findPath(enemy.pos, player.pos, {
smooth: true, // straight lines across open ground
maxNodes: 300, // a cap, so an unreachable goal cannot stall a frame
allowPartialPath: true, // unreachable: the way to the nearest cell (found false)
avoid: others.map((o) => o.pos), avoidWeight: 6, // spread out, this search only
});
// path[0] is the start: head for path[1]
The plugin keeps a grid for each level loaded, so a game that gets its grid from the level never builds one by hand:
import { PathfindingPlugin } from "@melonjs/pathfinding-plugin";
// from the "walls" tile layer, or (no `layer`) from the collision shapes;
// `subdivide` cuts each tile into 4 x 4 cells (1.1+), for doorways narrower
// than a tile
plugin.register(PathfindingPlugin, "pathfinding", { subdivide: 4 });
// once a level is loaded (null for a level it could not build a grid for)
const grid = plugin.cache.pathfinding.grid;
// a door opens: a body that collides with nothing is no wall (1.1+)
door.body.setCollisionMask(collision.types.NO_OBJECT);
grid.refresh();
Following a path is the game's part. Walk to each point in turn, and when the agent stops getting closer (its body caught on a corner the point-sized path runs past), find a new path from where it stands:
update(dt) {
const next = this.route[0];
if (next) {
const d = next.distance(this.pos);
if (d < SPEED * 1.5) {
this.route.shift(); // reached: on to the next
this.closest = Infinity;
} else if (d < this.closest - 0.5) {
this.closest = d; this.stuck = 0; // getting there
} else if (++this.stuck > 12) {
this.route = grid.findPath(this.pos, this.destination,
{ smooth: true, diagonalMode: "onlyIfNoObstacles" }).path.slice(1);
this.closest = Infinity; this.stuck = 0; // a new way from here
}
// ... set the velocity toward route[0]
}
return super.update(dt);
}
setTile / clearTile, or
a wall body added, is not seen until grid.refreshCell(col, row) or
grid.refresh(); setSolid / setWeight (and fillSolidRegion /
fillWeightRegion) change cells directly.fromTileLayer makes every non-empty cell solid by default (a walls
layer). On a floor layer, where every cell has a tile, pass solid, or
everything is solid.allowPartialPath is set.fromBodies after the level loads. It scans the shapes, not a
physics query, so it works before the world first steps; it reads bodyDef
shapes too, so it is the same on every adapter.WORLD_SHAPE bodies that collide with something. The
type and the mask are read from the live body before its bodyDef (which
keeps what it was written with), so a door opened with
body.setCollisionMask(collision.types.NO_OBJECT) is open after
grid.refresh(), with no solid callback. Before 1.1 it stayed a wall.
Pass solid: (renderable) => ... for any other rule.{ subdivide: 4 } on the plugin, or smaller tileWidth /
tileHeight for fromBodies. A search crosses n times more cells along
a path, n² more in all, so subdivide no further than the walls need.setSolid, not Infinity.PathfindingPlugin builds the grid from layer (a tile layer's name),
from the collision shapes without it (with subdivide), or with
build: (container) => grid. It only rebuilds when a level loads (and at
once if one is loaded): call grid.refresh() after the level changes, or
rebuild() for a new grid. A Grid works on its own. On a level it cannot
build for (staggered, hexagonal, or a bad subdivide) it warns and keeps
grid null.PathfindingDebug draws solid and heavy cells, the cells a search looked
at (trace: true) and the paths.fromTileLayer and the plugin (from a layer or
the shapes) see an isometric map and lay the cells out as diamonds; for
new Grid or fromBodies, pass cellShape: "isometric". Staggered and hexagonal maps are not
supported (fromTileLayer throws).@melonjs/capacitor-pluginBridges 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-platforms
for native apps and the other platforms.
With pauseOnBackground (the default), going to the background pauses the
game and coming back resumes it, but only if this pause was the plugin's: a
game the player had paused stays paused.
@melonjs/planck-adapter, @melonjs/matter-adapter and
@melonjs/rapier2d-adapter swap the physics world wholesale, and
@melonjs/rapier3d-adapter does it for a Camera3d game whose bodies turn in
3D (3D shapes only). Pick one per game (app.world.setAdapter() can switch it later). 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
every adapter, so entity code does not have to branch. The exceptions are in
melonjs-physics: Box3d, Sphere and Point shapes are built-in only,
type: "kinematic" is planck and Rapier only, and the adapters' queryAABB
returns only renderables with a body. The Rapier adapter's WebAssembly loads
asynchronously, so it must be made with await RapierAdapter.create().
create() is on every adapter from planck-adapter 1.7, matter-adapter 1.6 and
rapier2d-adapter 1.0 (an older planck or matter adapter is made with
new X(options)), and world.setAdapter() from melonJS 20.14.
Two queries are not portable: querySphere and raycast3d exist only on the
built-in and Rapier 3D adapters (planck, matter and Rapier 2D 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.
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 |
|---|---|
plugin <name> already registered | the registry is global; registered twice, often across hot reloads |
Plugin version mismatch | the 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 numbers | app defaulted to game, the last Application to finish init() |
world.adapter.querySphere is not a function | built-in and Rapier 3D adapters only; planck, matter and Rapier 2D are 2D-only |
| a Tiled map opens in Tiled but not melonJS | compressed layers, tiled-inflate plugin missing |
| a path goes through walls | the grid does not know them: a floor layer needs solid, a changed tile needs refreshCell, fromBodies walls must be WORLD_SHAPE bodies (or pass solid) |
| a path cuts across a wall corner | diagonalMode is "always" or "atLeastOneWalkable": use "onlyIfNoObstacles" |
no path found (empty path, found false) | the goal is walled off, solid, or past maxNodes; allowPartialPath: true returns the way to the nearest point |
everything is solid on a fromTileLayer grid | a floor layer, where every cell has a tile: pass solid |
| an agent turns back at the start | path[0] is where it stands: head for path[1] |
| an opened door still blocks the path | pathfinding-plugin < 1.1 counted it a wall (it read the bodyDef, and ignored the mask): upgrade, and grid.refresh() once it opens |
| every doorway is closed on the grid | doorways narrower than a cell: subdivide on the plugin |
searches got slow after subdivide | n times finer is n² times the cells: subdivide no further than the walls need, or cap with maxNodes |
| an agent stops at a wall corner | it is not a point: on getting no closer, find a new path from where it stands |
| a path is offset from an isometric map | the grid is square: new Grid / fromBodies without cellShape: "isometric" |
plugin.cache.pathfinding.grid is null, with a warning | a staggered or hexagonal level, layer names no layer of it, or subdivide is not a whole number of 1 or more |
| a path is offset from the map | the grid's x / y are not the layer's: built before the layer was in its container, or the container moved since |
| plugin setup never runs | setup written in an init() method — there is no such hook |
Plugin should extend the BasePlugin Class ! when registering an adapter | adapters are a construction setting (or world.setAdapter()), not a plugin |
PlanckAdapter.create is not a function (or MatterAdapter) | planck-adapter < 1.7 or matter-adapter < 1.6; upgrade, or new PlanckAdapter(options) |
TypeError reading renderer from plugin.register(SpinePlugin) | registered before await app.init(); the plugin's app is still unset |
| physics behaves differently after adding an adapter | expected — units and force scales differ; re-tune |
| a Spine object slides off screen when the camera moves, or ignores its container (WebGL / WebGPU) | spine-plugin < 4.0.1 drew without the camera's and the parents' transform; upgrade |
a Spine object ignores setOpacity() / alpha | spine-plugin < 4.0.1; upgrade |
| a game paused from its menu is running again after the app comes back from the background | capacitor-plugin < 1.0.1 resumed on every return; upgrade |
| touch controls miss the finger after browser zoom or a move to another screen | gamepad-plugin < 1.2.1; upgrade |
melonjs-physics — the adapters and their behavioural differencesmelonjs-tilemaps — where the inflate plugin becomes mandatorymelonjs-performance — using the debug panel to measuremelonjs-platforms — Capacitor and native packaging, and the other platformsmelonjs-3d-assets — why skeletal characters go through SpineWhat SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub melonjs/melonjs --plugin melonjs27 skills in this plugin
/melonjsUse this skill FIRST for any melonJS task, and when asked to build a game for the browser with no engine named; it says what melonJS is the right engine for, turns a game idea into a plan, and routes to the right specialised skill. melonJS is an open-source 2D, 2.5D and 3D HTML5 game engine running on WebGPU, WebGL 2 or Canvas, with no runtime dependencies. Covers Application setup, the scene graph, renderables, sprites, tilemaps, physics, audio, particles, shaders, and the 3D tier — perspective cameras, meshes and glTF scenes. Triggers on: melonjs, melonJS, me.game, Application, app.init, app.world, Renderable, Sprite, Stage, state.change, Camera2d, Camera3d, Mesh, tilemap, Tiled, TMX, ParticleEmitter, ShaderEffect, make a game, build a game, browser game, web game, HTML5 game, HTML5 game engine, JavaScript game, TypeScript game, 2D game, platformer, top-down game, puzzle game, shooter, arcade game, game jam, playable ad, which game engine./melonjs-20-migrationUse 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./melonjs-3dUse this skill for anything 3D or 2.5D in melonJS — Camera3d, Mesh, InstancedMesh, Sprite3d billboards, Light3d, ground shadows, glTF/GLB scenes, and depth sorting. Covers the Y-down/+Z-forward convention (OpenGL's inverse), the cameraClass opt-in, orthographic (isometric) projection, clip planes, and the Canvas fallback's limits. Triggers on: Camera3d, toon, cel shading, toonBands, outlineWidth, outlineMode, rimLight, orthographic, isometric, orthoHeight, orthoWidth, projection, Mesh, InstancedMesh, Sprite3d, Trail3d, Light3d, billboard, glTF, glb, 3D, 2.5D, depth, cameraClass, fov, setClipPlanes, setFog, fog, heightFalloff, transparent, transparency, blendMode, castGroundShadow, shadowGroundPoint, lit, emissive, specular, shininess, normalMap, alphaCutoff, depthTest, vertexColors, worldToScreen, screenToRay, screenToWorld, pick, pickable, Ray3d, intersectRay, hit3d, followOffset, setBasis, getBasis, lookAt, orbit, up vector, gimbal, slerp, turn a direction, physics, rapier3d, Capsule3d, TriangleMesh3d./melonjs-3d-assetsUse this skill when loading 3D models into melonJS — glTF and GLB scenes, OBJ/MTL models, materials, imported lights, node animation, skinned characters, crossfades and attachments, ground shadows and GPU instancing. Covers level.load options including the async flag, the rightHanded conversion, and exactly what the loader does and does not support. Triggers on: glTF, gltf, glb, OBJ, MTL, 3D model, getGLTF, getOBJ, getMTL, GLTFModel, GLTFScene, level.load glb, rightHanded, lightIntensityScale, castGroundShadow, shadowGroundY, EXT_mesh_gpu_instancing, KHR_lights_punctual, alphaMode, doubleSided, map_d, map_bump, normalize, animationspeed, skinning, skinned mesh, skin, JOINTS_0, WEIGHTS_0, rigged character, Mixamo, crossfade, blend animations, reverseAnimation, setAnimationTime, play backwards, attach to bone, addChildToNode, getNodeTransform, getNodeNames, Blender export, 3D asset./melonjs-audioUse this skill for sound and music in melonJS — loading audio, playing effects, background tracks, audio sprites, volume and muting, spatial audio, procedural tone/noise generation, and effects such as reverb or a compressor on the whole mix. Covers the mandatory audio.init format list, the directory-not-file src convention, playTrack versus play, the fixed listener and pixel-scale distances of positional sound, and browser autoplay unlocking. Triggers on: audio, sound, audio.init, audio.play, playTrack, stopTrack, audio.load, sfx, music, volume, mute, fade, rate, pitch, sprite audio, stereo, panner, position, listener, refDistance, reverb, echo, delay, compressor, distortion, filter, audio effect, audio.tone, audio.noise, getAudioContext, getMasterGain, hasAudio, hasFormat, autoplay, no sound, sound stopped working, context suspended, silent after idle, clips silent but tones play./melonjs-camera-and-drawingUse this skill for camera control and immediate-mode drawing in melonJS — following a target, viewport bounds, shake and fade, secondary cameras and what each one draws, and drawing shapes, lines and gradients inside a custom draw(). Covers world versus screen coordinate conversion, clipping and masking, baking with CanvasRenderTarget, and reading pixels back. Triggers on: Camera2d, viewport, follow, offset, look ahead, setBounds, minimap, second camera, split screen, cullMask, visibilityLayer, hide from a camera, zoom, roll, shake, fadeIn, fadeOut, CameraEffect, addCameraEffect, MaskEffect, iris, image mask, PixelateTransitionEffect, worldToLocal, localToWorld, worldToScreen, screenToRay, screenToWorld, colorMatrix, renderer.fill, renderer.stroke, setGlobalAlpha, fillArc, Rect, Ellipse, Polygon, Line, Path2D, SVG path, Gradient, clipRect, mask, CanvasRenderTarget, NoiseTexture2d, lookAt, setBasis, orbit, toImageData, getImageData, toBlob, toDataURL, screenshot, read pixels.Other plugins' skills for the same job