melonjs-ui-and-text
Ce qu’il fait
Ce guide explique comment ajouter des éléments d'affichage tête haute, des boutons, des menus, des panneaux et des textes à un jeu melonJS. Il s'adresse aux développeurs de jeux qui créent des menus, des scores et des éléments d'interface.
Quand l’utiliser
- ✓Quand un développeur veut un bouton ou un menu cliquable sur l'écran de jeu.
- ✓Quand un développeur veut une barre de vie ou une barre de progression dans le jeu.
- ✓Quand le texte avec contour d'un développeur paraît coupé ou trop fin.
Lien du skill
https://github.com/melonjs/melonJS/blob/master/packages/melonjs/skills/melonjs-ui-and-text/SKILL.mdCopiez-le et collez-le dans votre IA (Claude, ChatGPT ou Cursor) en lui demandant de suivre les instructions.
Comment l’utiliser
Le plus simple : copiez le message et collez-le dans votre IA. Elle lit le skill et suit les instructions.
Message prêt à coller
Pour Claude Code, Codex ou Cursor : lancez-la dans le dossier du projet et le skill est installé.
Téléchargez le SKILL.md et placez-le dans le dossier de skills de votre agent.
Exemple de demande à votre IA
“Ajoutez un affichage du score et un bouton de démarrage cliquable à mon écran de menu melonJS.”
5 nouveaux skills par semaine. 1 minute de lecture.
Comment ça marche
Le skill montre comment créer des textes, des boutons, des curseurs et des panneaux, et comment les placer sur un écran qui reste fixe pendant que le monde du jeu se déplace.
Contenu technique (SKILL.md original)
Texte original de l’auteur, en anglais, directement depuis 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
Questions fréquentes
Pourquoi mon texte avec contour paraît-il incorrect ?
Le skill explique que le contour est centré sur le bord de la lettre, donc seule la moitié de sa largeur est visible.
Quel élément reçoit un clic lorsque deux se chevauchent ?
Le skill indique que, sur des panneaux qui se chevauchent, le pointeur va à l'un d'eux, et il explique comment le gérer.
Puis-je utiliser une police web personnalisée ?
Oui. Le skill mentionne le chargement de polices web pour les éléments de texte.
Détails
Description originale de l’auteur
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
Popularité
- Étoiles GitHub
- 6.4k
- Position au classement
- #14217
- Licence
- MIT
- Mis à jour
- 02/11/2026
Commentaires
- …
Autres skills de ce dépôt
melonjs-20-migration
6.4kAide votre agent à écrire du code de jeu melonJS pour la version 20 et à éviter les méthodes obsolètes des versions précédentes, comme le démarrage asynchrone obligatoire.
melonjs-3d-assets
6.4kAide votre agent à charger des modèles 3D comme les fichiers glTF, GLB et OBJ dans un jeu melonJS, avec des options d'échelle et d'éclairage.
melonjs-3d
6.4kAide votre agent à construire des scènes 3D ou 2,5D dans un jeu melonJS, avec les caméras, les maillages, les lumières et la profondeur, selon les règles d'axes du moteur.
melonjs-audio
6.4kAide votre agent à ajouter des effets sonores et de la musique à un jeu melonJS, avec la configuration audio, les pistes de fond, le réglage du volume et le son spatial.
Skills similaires
diffs
394kPermet à votre agent de produire un diff réel et partageable de vos modifications, sous forme de lien ou d'image, plutôt qu'un résumé écrit à la main.
coding-agent
394kAide votre agent à confier une tâche de programmation plus importante à Codex, Claude Code ou OpenCode comme travailleur en arrière-plan, puis à suivre sa progression.
gh-issues
394kAide votre agent à trouver des tickets GitHub, choisir ceux à traiter et ouvrir des pull requests avec des correctifs, y compris le suivi des commentaires de relecture.