melonjs-20-migration
Skill này làm gì
Skill liệt kê những thay đổi trong melonJS phiên bản 20 và các hàm cũ không còn hoạt động. Dành cho lập trình viên trò chơi dùng công cụ trò chơi trình duyệt melonJS.
Khi nào nên dùng
- ✓Khi lập trình viên đang nâng cấp một trò chơi melonJS từ phiên bản 19 trở xuống.
- ✓Khi lập trình viên viết mã melonJS và một phương thức mong đợi không tồn tại.
- ✓Khi lập trình viên khởi động trò chơi melonJS và màn hình vẫn trống sau khi thiết lập.
Liên kết skill
https://github.com/melonjs/melonJS/blob/master/packages/melonjs/skills/melonjs-20-migration/SKILL.mdSao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.
Cách dùng
Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.
Tin nhắn có sẵn để dán
Dành cho Claude Code, Codex hoặc Cursor: chạy lệnh trong thư mục dự án của bạn và skill sẽ được cài đặt.
Tải tệp SKILL.md về và thả vào thư mục skill của agent.
Ví dụ cách nhờ AI
“Trò chơi melonJS của tôi hiện màn hình trống sau khi tôi nâng cấp. Phiên bản 20 đã thay đổi những gì?”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
Skill liệt kê các thay đổi chính theo thứ tự khả năng gặp phải, chẳng hạn việc thiếu await bắt buộc khi thiết lập ứng dụng, và chỉ ra các API cũ đã bị gỡ hoặc đổi tên.
Nội dung kỹ thuật (SKILL.md gốc)
Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.
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:
| 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 |
— | response.depth / response.normal |
setLineWidth() |
17.3.0 | the lineWidth property |
Two of these deserve emphasis:
Entityis still exported, so code using it compiles and runs while being the wrong shape for 20.x. Compose aSprite/Renderablewith aBodyinstead.- The capitalised
Mathshadows the globalMathif 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.
Câu hỏi thường gặp
Lỗi phổ biến nhất là gì?
Skill nói việc thiếu await khi khởi tạo ứng dụng là vấn đề thường gặp nhất sau khi nâng cấp.
Vì sao màn hình bị trống?
Trong phiên bản 20, tạo ứng dụng không khởi chạy nó, nên không có gì được vẽ cho đến khi chờ khởi tạo xong.
Nó có bao gồm tùy chọn WebGPU không?
Có. Nó lưu ý nền tảng WebGL 2 và backend WebGPU.
Chi tiết
Mô tả gốc của tác giả
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.
repo: melonjs/melonJS
Độ phổ biến
- Sao GitHub
- 6.4k
- Vị trí xếp hạng
- #14194
- Giấy phép
- MIT
- Cập nhật
- 2/11/2026
Bình luận
- …
Thêm skill từ kho mã này
melonjs-3d-assets
6.4kGiúp agent của bạn tải mô hình 3D như file glTF, GLB và OBJ vào trò chơi trình duyệt melonJS, kèm tùy chọn tỷ lệ và ánh sáng.
melonjs-3d
6.4kGiúp agent của bạn xây dựng cảnh 3D hoặc 2.5D trong trò chơi trình duyệt melonJS, gồm camera, lưới, đèn và độ sâu, theo quy tắc trục của công cụ.
melonjs-audio
6.4kGiúp agent của bạn thêm hiệu ứng âm thanh và nhạc nền vào trò chơi melonJS, gồm thiết lập âm thanh, nhạc nền, điều chỉnh âm lượng và âm thanh không gian.
melonjs-camera-and-drawing
6.4kGiúp agent của bạn điều khiển camera trò chơi melonJS, chẳng hạn bám theo người chơi, và vẽ các hình hoặc đường kẻ tùy chỉnh trong trò chơi.
Skill tương tự
diffs
394kGiúp agent của bạn tạo một diff có thể chia sẻ về các chỉnh sửa, dưới dạng liên kết xem hoặc file ảnh, thay vì một bản tóm tắt viết tay.
coding-agent
394kGiúp agent của bạn giao một việc lập trình lớn cho Codex, Claude Code hoặc OpenCode chạy nền, rồi theo dõi tiến độ của nó.
gh-issues
394kGiúp agent của bạn tìm issue trên GitHub, chọn những issue cần xử lý và mở pull request với bản sửa, kể cả theo dõi nhận xét đánh giá.