melonjs-display-and-scaling
Skill này làm gì
Skill giải thích các thiết lập kiểm soát cách trò chơi melonJS được đặt kích thước và làm sắc nét trên màn hình. Dành cho lập trình viên có trò chơi bị mờ hoặc không vừa cửa sổ trình duyệt.
Khi nào nên dùng
- ✓Khi trò chơi melonJS bị mờ trên màn hình độ phân giải cao.
- ✓Khi trò chơi melonJS bị cắt hoặc không lấp đầy trang theo cách lập trình viên muốn.
- ✓Khi lập trình viên muốn kích thước đúng từng pixel cho pixel art trong trò chơi trình duyệt.
Liên kết skill
https://github.com/melonjs/melonJS/blob/master/packages/melonjs/skills/melonjs-display-and-scaling/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
“Pixel art melonJS của tôi bị mờ và không vừa cửa sổ. Tôi nên đổi thiết lập nào?”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
Skill tách các thiết lập theo chức năng, như kích thước thiết kế, phương pháp co giãn, làm tròn và lọc texture, rồi giải thích thiết lập nào cần đổi cho từng vấ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.
Display and scaling
Seven settings decide how a game looks on screen, and they are easy to get individually right and collectively wrong. This is what each one actually does, and which one to reach for.
The four jobs
A pixel travels from your source art to a physical pixel through four separate decisions. Knowing which setting owns which is most of the work.
| job | setting | what it decides |
|---|---|---|
| how big the frame is drawn | width/height on Application |
the design resolution everything is authored against |
| how it uses the space | scale, scaleMethod, scaleTarget |
fit, fill, stretch, and what it measures to decide |
| may the factor be fractional | scaleRounding |
whole device pixels per source pixel, or any factor |
| how a texture is sampled | antiAlias, textureFilter |
nearest or linear, and the CSS upscale filter |
subPixel is a fifth, orthogonal to all of them: it decides whether a
renderable may sit on a fractional position WITHIN the frame. syncToDisplay
is about the frames in a row rather than one frame: whether motion advances
by the same amount on each.
Design resolution
const app = new Application(480, 270, { scale: "auto" });
The game is drawn at 480x270 whatever the window is, and the canvas is scaled to the container. Everything in world coordinates is in those units. This is the usual arrangement: author once, scale to whatever you are given.
scale and scaleMethod
scale: "auto" turns on automatic scaling; a number is a fixed multiplier and
scaleMethod is then ignored.
scaleMethod decides how the available space is used:
"fit"keeps the design resolution and the aspect ratio, scaling to the largest factor that fits. Leftover space becomes margin. This is the one to use when the game is authored for a fixed frame."fill-min"/"fill-max"keep the aspect ratio but RESIZE the renderer, so the design resolution changes with the window and the game sees more or less of the world."flex","flex-width","flex-height"resize the renderer on one or both axes."stretch"scales each axis independently, so the aspect ratio is not preserved and circles become ovals."manual"does nothing automatic.
The distinction that matters: fit scales a fixed frame; everything else
changes how much of the world is visible. A game whose layout assumes a
known frame wants fit.
scaleTarget: what gets measured
Automatic scaling measures the parent of the element the canvas is mounted in, not the element itself. If that grandparent is not the box you meant, the canvas is sized wrongly, and the failure is quiet.
The case that bites: a canvas container that is position: fixed or
absolute contributes no height to its parent, so the parent measures only
whatever else is in it. If that parent is <body>, the engine falls back to
the window size and the canvas ends up larger than the box it lives in,
cropped by whatever sits above it.
new Application(1024, 576, {
parent: "screen",
scale: "auto",
// measure THIS, rather than guessing from the DOM shape
scaleTarget: document.getElementById("stage"),
});
Either name the element with scaleTarget, or give the canvas container a
parent whose box is the area you want filled. If the canvas is cropped or
overflows on resize, this is the first thing to check.
scaleRounding: whole device pixels
new Application(480, 270, {
scale: "auto",
scaleMethod: "fit",
scaleRounding: "integer", // default "fractional"
});
"fractional" fills the container exactly, at whatever factor that takes. A
480 wide design in a 1280 wide container is scaled by 2.667, so some source
pixels cover three screen pixels and some cover two. Pixel art shows this as
uneven glyph stems and shimmering edges, and browsers resolve the unevenness
differently, so the same scene can look crisp in one and soft in another.
"integer" rounds the factor DOWN so every source pixel covers the same whole
number of device pixels, and letterboxes with the space left over. That trade,
crisp pixels for black bars, is the whole decision.
What it costs
More than "some letterboxing", and the size of it is decided by
devicePixelRatio as much as by the window. A higher ratio has more device
pixels to round among, so it lands closer to the factor it wanted. For a
480x270 design, which is exactly a quarter of 1920x1080:
| container | ratio | f
Câu hỏi thường gặp
Độ phân giải thiết kế là gì?
Đó là kích thước cố định mà trò chơi được vẽ, sau đó được co giãn để vừa cửa sổ.
Làm sao để có pixel art sắc nét?
Skill nhắc đến co giãn nguyên và lọc texture láng giềng gần nhất như lựa chọn thường dùng.
Vì sao chuyển động trông không đều?
Skill nhắc đến một thiết lập đồng bộ để chuyển động ổn định giữa các khung hình.
Chi tiết
Mô tả gốc của tác giả
Use this skill when a melonJS game looks blurry, soft, shimmering or cropped, or when choosing how the canvas fills its page. Covers the design resolution, scale and scaleMethod, scaleTarget, scaleRounding for pixel-perfect integer scaling, antiAlias, textureFilter and linear-mipmap for what is drawn small, subPixel, syncToDisplay for steady motion, devicePixelRatio, and which setting does which job. Triggers on: blurry, soft, fuzzy, shimmering, pixel art, pixel perfect, crisp, nearest, linear, scale, scaleMethod, scaleTarget, scaleRounding, integer scaling, antiAlias, textureFilter, linear-mi
repo: melonjs/melonJS
Độ phổ biến
- Sao GitHub
- 6.4k
- Vị trí xếp hạng
- #14200
- 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-20-migration
6.4kGiúp agent của bạn viết mã trò chơi melonJS cho phiên bản 20 và tránh các phương thức cũ, như bước khởi động bất đồng bộ bắt buộc.
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.
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á.