melonjs-lighting
O que ela faz
Explica como adicionar uma camada de luz ambiente escura e luzes que atravessam essa escuridão, além de como sprites com mapas normais reagem. É para desenvolvedores de jogos que criam cenas 2D com clima ou iluminação.
Quando usar
- ✓Quando um desenvolvedor quer um quarto escuro com uma tocha ou lâmpada em um jogo melonJS.
- ✓Quando um desenvolvedor quer destaques especulares em sprites que têm mapas normais.
- ✓Quando a luz de um desenvolvedor desaparece depois de trocar para uma câmera 3D.
Link da skill
https://github.com/melonjs/melonJS/blob/master/packages/melonjs/skills/melonjs-lighting/SKILL.mdCopie e cole na sua IA (Claude, ChatGPT ou Cursor) pedindo para seguir as instruções.
Como usar
O jeito mais fácil: copie a mensagem e cole na sua IA. Ela lê a skill e segue as instruções.
Mensagem pronta para colar
Para Claude Code, Codex ou Cursor: rode na pasta do projeto e a skill fica instalada.
Baixe o SKILL.md e coloque na pasta de skills do seu agente.
Exemplo do que pedir para a IA
“Deixe meu nível do melonJS azul-escuro, com uma luz quente que siga a lâmpada do quarto.”
5 skills novas por semana. 1 minuto de leitura.
Como funciona
A skill orienta a IA a definir a cor ambiente do palco para criar escuridão e depois adicionar objetos de luz em posições escolhidas, com cor e tamanho definidos.
Conteúdo técnico (SKILL.md original)
Texto original do autor, em inglês, direto do GitHub.
2D dynamic lighting
Light2dis a world renderable that cuts through a stage's ambient darkness. The glow and the cutout work on every backend; only per-pixel normal-map shading needs a GPU one. It is 2D-only.
The model: ambient darkness plus cutouts
The Stage holds an ambient colour — a dark sheet painted over the scene after
the world is drawn — and each active Light2d punches a hole in it at its
visible area. The lights themselves are drawn additively on top.
class PlayScreen extends Stage {
onResetEvent(app) {
this.ambientLight.parseCSS("#1a1a2e"); // the darkness
app.world.addChild(new Light2d(x, y, radiusX, radiusY, "#ffddaa", 0.9));
}
}
The constructor is Light2d(x, y, radiusX, radiusY = radiusX, color = "#FFF", intensity = 0.7), and pos is the light's centre — its anchorPoint is
(0.5, 0.5), and centerX / centerY are overridden to return pos directly.
Give radiusY a different value for a stretched, elliptical light.
A Light2d added to the world registers itself with the stage's ambient
overlay on activate, so you add it like any other renderable and it takes part
in the lighting pass. It draws additively (blendMode = "lighter"); set
light.illuminationOnly = true to suppress the visible glow while still lighting
normal-mapped sprites.
Stage.ambientLight defaults to fully transparent black, and drawLighting()
returns immediately while its alpha is 0 — so with no ambient colour set there
is nothing to cut through and the lights just look like soft additive blobs.
Soft edges: softness
A light's hole in the darkness is hard-edged by default: full light inside its
radius, full darkness outside. light.softness (0 to 1) fades it instead:
const torch = new Light2d(x, y, 220, 220, "#ffb46a", 0.4);
torch.softness = 0.8; // lit core of 20% of the radius, then fading out
1thins the darkness straight from the centre to the edge, the same falloff as the glow; in between, a fully lit core of1 - softnessof the radius.- Hard and soft lights mix in one scene. Where lights overlap, what is left of the darkness is what each leaves, multiplied, so two half-lights make three quarters light.
- The hole is the light's size. For an opening wider than the glow (a torch whose
light reaches further than its flame's halo), add a second, bigger light with
illuminationOnly = true: it cuts the darkness and draws nothing. - Up to 32 lights in view are cut by one soft pass; lights outside the view do not count. A scene with no soft light draws exactly as before.
- To keep a camera out of the darkness (a minimap showing the level lit),
override
drawLightingon the stage and skip that camera. - To keep one light out of a camera, put it, or a container it is in, on a
visibilityLayerthe camera'scullMaskleaves out: there it neither glows, nor cuts the darkness, nor lights normal-mapped sprites (seemelonjs-camera-and-drawing). This is for aLight2d: aLight3dlights the meshes of every camera.
Multiple lights
Add as many as you need — the glow quads and the ambient cutouts accumulate with no fixed cap.
The normal-map pipeline is capped: lights are packed into a std140 uniform
block sized for MAX_LIGHTS = 32, and anything past the 32nd is silently dropped
from the per-pixel shading (it still draws its glow and punches its cutout). The
cap is an allocation, not a budget — the fragment loop still runs once per pixel
per live light.
Lights are positioned like any renderable, so they can follow an entity by
updating pos, or be added as children of one.
Per-pixel lighting with normal maps
For sprites that respond to light direction rather than just brightness, supply a normal map alongside the diffuse texture:
await loader.preload([
{ name: "hero", type: "image", src: "data/img/hero.png" },
{ name: "hero_n", type: "image", src: "data/img/hero_n.png" },
]);
const hero = new Sprite(x, y, {
image: "hero",
normalMap: "hero_n", // ← enables per-pixel lighting on this sprite
framewidth: 32, frameheight: 32,
});
normalMap takes a loader key, or any image-like source (HTMLImageElement,
canvas, ImageBitmap, a Texture2d). Assigning anything else — including an
HTMLVideoElement, which would freeze on frame 0 — throws a TypeError.
Normal maps are typically authored in SpriteIlluminator. The sidecar pattern above — one
Perguntas frequentes
Por que o sombreamento por pixel não funciona em todos os lugares?
A skill diz que o sombreamento com mapas normais precisa de um backend com GPU, enquanto o brilho e o recorte funcionam em todos os backends.
Uma luz pode ser esticada?
Sim. Dar um valor diferente ao raio vertical cria uma luz elíptica.
A iluminação funciona em 3D?
Não. A skill diz que a luz 2D não sobrevive a uma câmera 3D.
Detalhes
Descrição original do autor
Use this skill for 2D dynamic lighting in melonJS — Light2d, ambient light on a Stage, multiple lights, and per-pixel normal-mapped sprites authored in SpriteIlluminator. Covers specular highlights via shininess, the ambient-cutout model, which parts need a GPU backend, and why Light2d does not survive a Camera3d. Triggers on: Light2d, specular, shininess, highlight, glint, lighting, ambientLight, ambientLightingColor, normalMap, SpriteIlluminator, per-pixel lighting, drawLight, torch, glow, darkness.
repo: melonjs/melonJS
Popularidade
- Estrelas no GitHub
- 6,4 mil
- Posição no ranking
- #14205
- Licença
- MIT
- Atualizada em
- 02/11/2026
Comentários
- …
Mais skills deste repositório
melonjs-20-migration
6,4 milAjuda seu agente a escrever código de jogo em melonJS para a versão 20 e a evitar métodos desatualizados de versões antigas, como a inicialização assíncrona obrigatória.
melonjs-3d-assets
6,4 milAjuda seu agente a carregar modelos 3D, como arquivos glTF, GLB e OBJ, em um jogo melonJS para navegador, com opções de escala e iluminação.
melonjs-3d
6,4 milAjuda seu agente a criar cenas 3D ou 2,5D em um jogo melonJS para navegador, cobrindo câmeras, malhas, luzes e profundidade, usando as regras de eixos do próprio motor.
melonjs-audio
6,4 milAjuda seu agente a adicionar efeitos sonoros e músicas a um jogo melonJS, incluindo a configuração de áudio, faixas de fundo, controle de volume e som espacial.
Skills parecidas
diffs
394 milPermite que seu agente gere um diff real e compartilhável das edições, como link de visualização ou arquivo de imagem, em vez de um resumo escrito à mão.
coding-agent
394 milAjuda seu agente a passar um trabalho grande de programação para o Codex, Claude Code ou OpenCode em segundo plano e acompanhar o andamento.
gh-issues
394 milAjuda seu agente a encontrar issues do GitHub, escolher quais resolver e abrir pull requests com correções, acompanhando os comentários de revisão.