melonjs-ui-and-text
하는 일
melonJS 게임에 HUD 요소, 버튼, 메뉴, 패널, 텍스트를 추가하는 방법을 설명합니다. 메뉴, 점수, 인터페이스 요소를 만드는 게임 개발자를 위한 스킬입니다.
사용하는 경우
- ✓개발자가 게임 화면에 클릭 가능한 버튼이나 메뉴를 넣고 싶을 때.
- ✓개발자가 게임에 체력 바나 진행 바를 넣고 싶을 때.
- ✓개발자의 외곽선 텍스트가 잘려 보이거나 너무 얇게 보일 때.
스킬 링크
https://github.com/melonjs/melonJS/blob/master/packages/melonjs/skills/melonjs-ui-and-text/SKILL.md복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.
사용 방법
가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.
바로 붙여넣을 수 있는 메시지
Claude Code, Codex, Cursor용입니다. 프로젝트 폴더에서 실행하면 스킬이 설치됩니다.
SKILL.md를 다운로드해 에이전트의 스킬 폴더에 넣으세요.
AI에게 요청하는 예시
“제 melonJS 메뉴 화면에 점수 표시와 클릭 가능한 시작 버튼을 추가해 주세요.”
매주 새 스킬 5개. 읽는 데 1분.
작동 방식
스킬은 텍스트, 버튼, 슬라이더, 패널을 만드는 방법과, 게임 세계가 움직이는 동안 고정된 화면에 배치하는 방법을 보여 줍니다.
기술 내용 (원본 SKILL.md)
작성자의 영어 원문을 GitHub에서 그대로 가져왔습니다.
UI, HUD and text
Outlined text: behind the glyphs, or over them
An outline is centred on the glyph's edge, so half of it lies inside the
glyph. Text paints it behind the glyphs by default (paintOrder: "stroke"): the letters stay whole and the outline shows only around them, so
a thick outline works on any face. What shows is half of lineWidth: ask for
twice the width you want to see.
paintOrder: "fill" paints the glyphs first and the outline over them, as a
plain canvas does with fillText then strokeText, and as melonJS did before
20.13. Its inner half then covers the letters: on a small or thin face a
lineWidth of 3 already leaves them solid outline colour.
const style = {
font: "sans-serif", size: 32,
fillStyle: "#ffd23f", strokeStyle: "#1b1b1b", lineWidth: 6,
};
new Text(x, y, { ...style, text: "BEHIND" }); // the default
new Text(x, y, { ...style, paintOrder: "fill", text: "OVER" }); // the old look
The stroke used to cost you the top row of pixels as well, and a display face whose glyphs overshoot the nominal ascent did the same on its own: the render box was sized from the line height alone, with no allowance for either. That is fixed — the bake is padded by the ink's real extent and the blit shifts back by the same amount, so nothing is clipped and the reported bounds are unchanged. Write the string you mean:
new Text(x, y, { font: "Display", lineWidth: 1, lineHeight: 1.45, text: "" });
hud.setText("SCORE 100");
If you have a label carrying a leading \n to buy headroom, that workaround is
now dead weight — drop it, and take the line height back off the position you
shifted it by.
The outline's corners are set by lineJoin, the same property a canvas
context has, and miterLimit:
| setting | corners | use it for |
|---|---|---|
lineJoin: "round" (default) |
rounded: the outline is the same width all around | almost everything: HUDs, buttons, titles |
lineJoin: "bevel" |
cut flat | a harder edge with no spikes |
lineJoin: "miter" |
pointed, as a plain canvas strokes text | a sharp, angular look |
miterLimit: n (default 10) |
with "miter" only: a corner pointing further than n half line widths is cut flat instead |
taming the spikes "miter" grows on "A", "V", "M" |
At the canvas default of 10, a thick "miter" outline grows spikes several
times its width from sharp glyphs; 2 to 4 keeps the corners pointed and the
spikes short:
const outline = {
font: "sans-serif", size: 48,
fillStyle: "#ffffff", strokeStyle: "#000000", lineWidth: 6,
};
new Text(x, y, { ...outline, text: "ROUND" }); // the default
new Text(x, y, { ...outline, lineJoin: "bevel", text: "BEVEL" });
new Text(x, y, { ...outline, lineJoin: "miter", text: "MITER" }); // long spikes
new Text(x, y, { ...outline, lineJoin: "miter", miterLimit: 3, text: "MITER 3" });
Whichever you pick, the bake leaves room for it on all four sides, so no corner
is cut and the label's position and bounds do not move; pointed corners just
cost a bigger texture. Changed on a live label, they show from the next
setText().
Gradient text
fillStyle takes a Gradient as well as a colour — the same object
Renderer#setColor accepts, built the way the canvas API builds one:
const ramp = renderer.createLinearGradient(0, 0, 0, 24); // top to bottom
ramp.addColorStop(0, "#fffdf0");
ramp.addColorStop(1, "#f0a020");
new Text(x, y, { font: "Display", size: 24, fillStyle: ramp });
Coordinates are the label's own bake: (0, 0) is the top-left of the render
box, so the ramp above runs down one line. A multi-line label restarts it on
every line, reading like one Text per line — you do not have to author the
gradient over the block height. Pass gradientPerLine: false for a single ramp
spanning the whole block, which is what a plain canvas does and what a
deliberate fade across a two-line title wants.
The ramp colours the fill only — Text strokes in a separate pass, so
an outline keeps its own colour without any luminance trickery — and it works on
Canvas2D, which a post effect does not.
The gradient does not live in fillStyle
fillStyle ACCEPTS a Gradient; it never HOLDS one. The constructor routes it
to fillGradient and leaves fillStyle as the pooled Color it always is,
which is what keeps fillStyle.alpha gating the fill and keeps the colour
owned by the pool.
So changing the ramp la
자주 묻는 질문
외곽선 텍스트가 왜 이상하게 보이나요?
외곽선은 글자 가장자리를 기준으로 가운데 그려지므로, 너비의 절반만 보인다고 스킬은 설명합니다.
두 요소가 겹치면 어느 요소가 클릭을 받나요?
겹친 패널에서는 포인터가 둘 중 하나로 가며, 스킬은 이를 처리하는 방법을 설명합니다.
사용자 정의 웹 폰트를 쓸 수 있나요?
네. 스킬은 텍스트 요소에 웹 폰트를 불러오는 방법을 언급합니다.
상세 정보
작성자의 원본 설명
Use this skill for HUDs, buttons, menus, options screens, dialogue panels, progress bars and on-screen text in melonJS. Covers UIBaseElement/UISpriteElement/UITextButton, UICheckbox, UISlider, ProgressBar, UIPanel (skins, layout, scrolling), Draggable and DropTarget, the floating screen-space container pattern, which of two overlapping panels gets the pointer, Text and BitmapText, web font loading, and NineSliceSprite panels. Triggers on: UI, HUD, button, checkbox, radio button, UICheckbox, slider, UISlider, volume slider, options menu, settings screen, scrolling list, scroll panel, layout, co
repo: melonjs/melonJS
인기도
- GitHub 스타
- 6.4k
- 순위
- #14217
- 라이선스
- MIT
- 업데이트
- 2026. 11. 2.
댓글
- …
이 저장소의 다른 스킬
melonjs-20-migration
6.4k에이전트가 melonJS 20 버전에 맞는 게임 코드를 작성하고, 필수 비동기 시작 방식 등 이전 버전의 오래된 메서드를 피하도록 돕습니다.
melonjs-3d-assets
6.4k에이전트가 glTF, GLB, OBJ 같은 3D 모델 파일을 melonJS 브라우저 게임에 불러오고, 크기와 조명 옵션을 설정하도록 돕습니다.
melonjs-3d
6.4k에이전트가 melonJS 브라우저 게임에서 카메라, 메시, 조명, 깊이를 포함한 3D 또는 2.5D 장면을 엔진 고유의 축 규칙에 맞게 만들도록 돕습니다.
melonjs-audio
6.4k에이전트가 melonJS 게임에 효과음과 배경 음악을 추가하고, 오디오 설정, 음량 조절, 공간 음향까지 다루도록 돕습니다.